     }
 
     func startScan() {
-        guard !isScanning else { return }
+        guard !reachedDiscoveryLimit else { return }
+        guard !Singletons.centralManager.isScanning else { return }
+
         isScanning = true
-        guard !reachedDiscoveryLimit else { return }
 
         let future: FutureStream<Peripheral>
         let scanMode = ConfigStore.getScanMode()

            return
        }
        let peripherals = self.peripheralsSortedByRSSI
        if allPeripheralsDiscovered {
            for _ in 0..<maxConnections {
                let peripheralIndex = Int(arc4random_uniform(UInt32(peripherals.count)))
                let peripheral = peripherals[peripheralIndex]
                Logger.debug("Connecting peripheral: '\(peripheral.name)', \(peripheralIndex), \(peripheral.identifier.uuidString)")
                connectedPeripherals.insert(peripheral.identifier)
                connect(peripheral)
            }
        } else {
            for peripheral in peripherals where connectionCount < maxConnections {
                if !connectedPeripherals.contains(peripheral.identifier) && !discoveredPeripherals.contains(peripheral.identifier) {
                    Logger.debug("Connecting peripheral: '\(peripheral.name)', \(peripheral.identifier.uuidString)")
                    connectedPeripherals.insert(peripheral.identifier)
                    connect(peripheral)
                    connectionCount += 1
                }
            }
        }
    }

    }

    func afterPeripheralDiscovered(_ peripheral: Peripheral) -> Void {
        guard  Singletons.centralManager.peripherals.contains(peripheral) else { return }
        Logger.debug("Discovered peripheral: '\(peripheral.name)', \(peripheral.identifier.uuidString)")
        Notification.send("Discovered peripheral '\(peripheral.name)'")
        updateWhenActive()
