fixed error checking issue