Avoid code duplication by introducing generic defect caluclation