clean up code and final refactor