Move connection code into a method.
Move switcher cleanup into the disconnect handler.