Refactoring, added test code to safe close deals