Refactor url retry mechanism.