FIX: retry loop condition bug

A more robust check for the max attempts while in retying a retry loop.