             return
         }
 
+        self.cancelTimeout()
+
         //this was only needed, beacuse CBManager would drop connection if we lose all strong references to the device
         self.peripheralToConnect = nil
 

            central.stopScan()
            log("stop scan")

            if let worker = scanTimeoutWorker {
                worker.cancel()
                scanTimeoutWorker = nil
            }

            if RSSI.int32Value < -90  {
                self.log("Device too far.. sent warning to user")

    }
    
    deinit {
        self.cancelTimeout()
        self.dropAllConnections()
    }

    private func fail(withReason reason: BluetoothConnectionManagerError, severity: MeshSetupErrorSeverity) {
        log("Bluetooth connection manager error: \(reason)")
        self.delegate.bluetoothConnectionManagerError(sender: self, error: reason, severity: severity)
    }

    private func log(_ message: String) {
        if (MeshSetup.LogBluetoothConnectionManager) {
            NSLog("MeshSetupBluetoothConnectionManager: \(message)")
        }
    }


    func createConnection(with peripheralCredentials: MeshSetupPeripheralCredentials) {
        if (self.state != .Ready){
            fail(withReason: .FailedToStartScan, severity: .Error)
            return
        }

        self.peripheralToConnectCredentials = peripheralCredentials
        self.scanForPeripherals()
    }

    private func scanForPeripherals() {
        self.state = .Scanning

        log("BluetoothConnectionManager -- scanForPeripherals with services \(MeshSetup.particleMeshServiceUUID)")
        let options: NSDictionary = NSDictionary(objects: [NSNumber(value: true as Bool)], forKeys: [CBCentralManagerScanOptionAllowDuplicatesKey as NSCopying])
        self.centralManager.scanForPeripherals(withServices: [MeshSetup.particleMeshServiceUUID], options: options as? [String: AnyObject]) // []

        self.restartTimeout()
    }

    private func cancelTimeout() {
        if let worker = scanTimeoutWorker {
            worker.cancel()
            scanTimeoutWorker = nil
        }
    }
    private func restartTimeout() {
        self.cancelTimeout()

        scanTimeoutWorker = scanTimeoutWorkerFactory
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + MeshSetup.bluetoothScanTimeoutValue,
