Avoid code duplication by refactoring.