fix wait logic