Minor refactoring and restructuring