upgrade failsafe into function