code formatting and refactoring