Minor refactoring and cleanup.