Split off the new leader retry into a separate method.
A few more improvements.