Some miscellaneous refactoring