Refactorings to reduce code duplication.