Changed order of error checks