Fixed the retries code

Sorry about the earlier commit, the retries code now works as expected.