Change the order in which some error conditions are checked to improve