Refactor to avoid repetition.