Refactoring and code formatting