Refactoring plus more functionality