fixing a problem in error checking