Used wait instead of sleep.