rewrite ensure_connected