Added safeApply factory.