General tidy up, refactoring