Misc refactoring.