Fix returning wrong value for wait