refactoring and formatting