some minor refactoring and cleanup