Miscellaneous refactoring and reformatting