refactoring and clean up