Improve order of error checks