Reworked the retry code.