Minor refactoring and cleaning