Handling the retries logic