minor refactoring and cleanup.