Minor refactoring and polish