Minor refactoring and reformatting