refactoring with existing functionality