Detailed code cleaning and refactoring.