                 peer.displayName = service.name
                 peer.dnsService = service
                 self.peers.append(peer)
-                NSLog("BluepeerObject didFind: created new peer \(peer.displayName)")
+                NSLog("BluepeerObject didFind: created new peer \(peer.displayName). Peers.count after adding: \(self.peers.count)")
             } else {
                 NSLog("BluepeerObject didFind: found existing peer \(peer?.displayName) with same service - no-op!")
             }

            return
        }
        let peer = self.peers[peerIndex]
        let oldState = peer.state
        peer.state = .notConnected
        peer.keepaliveTimer?.invalidate()
        peer.keepaliveTimer = nil
        peer.socket = nil
        sock.delegate = nil
        NSLog("BluepeerObject: \(peer.displayName) @ \(peer.socket?.connectedHost) disconnected.")
        switch oldState {
        case .connected:
            self.peers.remove(at: peerIndex)
            self.dispatch_on_delegate_queue({
                self.sessionDelegate?.peerDidDisconnect?(peer.role, peer: peer)
            })
        case .notConnected:
            self.peers.remove(at: peerIndex)
            assert(false, "ERROR: state is being tracked wrong")
        case .connecting, .awaitingAuth:
            // don't remove peer in this case

            delegate.browserFoundPeer?(role, peer: peer, inviteBlock: { (timeoutForInvite) in
                do {
                    // pick the address to connect to INSIDE the block, because more addresses may have been added between announcement and inviteBlock being executed
                    guard let hhaddresses = peer.dnsService?.resolvedAddressInfo, hhaddresses.count > 0, var chosenAddress = hhaddresses.filter({ $0.isCandidateAddress(bluetoothOnly: self.bluetoothOnly) }).first else {
                        NSLog("BluepeerObject inviteBlock: ERROR, no resolvedAddresses or candidates!?!")
                        assert(false)
                        return
                    }
                    
                    // if we can use wifi, then use wifi if possible
                    if !self.bluetoothOnly && !chosenAddress.isWifiInterface() {
                        let wifiCandidates = hhaddresses.filter({ $0.isCandidateAddress(bluetoothOnly: self.bluetoothOnly) && $0.isWifiInterface() })
                        if wifiCandidates.count > 0 {
                            chosenAddress = wifiCandidates.first!
                        }
                    }
                    
                    NSLog("BluepeerObject inviteBlock: peer has \(hhaddresses.count) addresses, chose \(chosenAddress.addressAndPortString) on interface \(chosenAddress.interfaceName)")
                    let sockdata = chosenAddress.socketAsData()
                    
                    self.stopBrowsing() // stop browsing once user has done something. Destroys all HHService except this one!
