More cleaning and refactoring