Needs tidy up and unit test