clean up code and refactor