Fixing wrong error checks