refactor to clean up code