Fixes to error checking