Some relatively minor refactoring