Miscellaneous refactoring