Refactor duplicate code sections.