Cleaning and refactoring