updated wait/retry loop