Tidy up code; unit test coverage