fix some error checking