Patch SafeFunction to work with all test cases