Refactoring to remove code duplication.