Adding wait logic