Fixed a logic bug in the retry logic