tidy up and refactoring