             
             NotificationCenter.default.post(name: Clink.Notifications.didDiscoverPeer, object: peer, userInfo: peer.data)
             
-            if newlyDiscoveredPeripheral?.identifier == peripheral.identifier {
+            if self.activePairingTask != nil {
                 self.centralManager.stopScan()
-                newlyDiscoveredPeripheral = nil
+                self.activePairingTask?.timer.invalidate()
+                self.activePairingTask?.completion(OpperationResult.success(result: peer))
+                self.activePairingTask = nil
             }
             
             

    public final func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
        if self.logLevel == .verbose { print("calling \(#function)") }
        
        if newlyDiscoveredPeripheral?.identifier != peripheral.identifier {
            if let i = self.connectedPeers.index(where: { $0.id == peripheral.identifier }) { self.connectedPeers.remove(at: i) }
            
            let peer = ClinkPeer(id: peripheral.identifier)

        
        let peerManager = self.peerManager ?? self
        
        if var pairingTask = self.activePairingTask, peerManager.getSavedPeer(withId: peripheral.identifier) == nil {
            pairingTask.remotePeripheral = peripheral
        }
        
        peripheral.delegate = self
        central.connect(peripheral, options: nil)
    }
