clean up code and refactoring