fixed minor problem with error checking