some clean up and refactor