More careful error checking