Tidied up formatting, fixed a couple of bugs, added TODOs for things tha...

...t need doing or clarifying