Add more unit tests & tidy up