Fixed infinite wait bug