Added failsafe error check