Fix up connection state change handling and add some more tests