fixed error checking