Reviewed connection mechanism.

Nicer, and could be extended to support auto-reconnect.