minor refactoring and cleanup