clean up and refactor