refactoring and code clean up