Some misc code cleanup and improved connection error recovery.
Still need to properly handle SRV errors (like timeouts) and add back-off in case of auth errors.
This tag has no release notes.