corrected err check