Adding wait task to capture the valid flag.