Refactoring and formatting