Refactoring changes and tests