Removes code duplication by refactoring.