Rewrite reconnection handling and tests.