fix bug of wait routines