minor refactoring and reformatting