Code formatting and refactoring