use a wait instead of sleep