Minor refactoring and cleanup