Minor refactoring throughout