Updated safeApply factory.