refactoring and clean up.