Not totally happy with the complexity in approach, could maybe do with refactoring some of this out, but getting a little tired spending time on this.