minor refactoring and polish