tidy up and code merge