Refactor code to be more DRY.