refactoring and clean-up