added a very rudimentary test suite (and fixed a few bugs along the way)
tidy up/remove unused code