Various fixes and tidy up.  A few more tests passing.