refactoring for testing