fixes to error checking