Pretty much rewrote the whole thing from scratch - so much so I might as well call this an initial commit.