fix and tidy up unit tests