Fixes #259 and 242

Makes reconnection simpler, more efficient and provider-neutral.