refactor code to clean up