minor refactoring and formatting