Refactor to remove repetition.