error checking on wait