optimisation and unit test tidy up