Rewrite retry logic.