some code formatting, refactoring and styling