tweaked error check