Log cleaning and refactoring