tidy up and unit tests