 
     var peripheralsSortedByRSSI: [BCPeripheral] {
         return Singletons.centralManager.peripherals.sort() { (p1, p2) -> Bool in
-            return p1.RSSI >= p2.RSSI
+            if p1.RSSI == 127 && p2.RSSI != 127 {
+                return false
+            }  else if p1.RSSI != 127 && p2.RSSI == 127 {
+                return true
+            } else if p1.RSSI == 127 && p2.RSSI == 127 {
+                return true
+            } else {
+                return p1.RSSI >= p2.RSSI
+            }
         }
     }
 

    }

    func connect(peripheral: BCPeripheral) {
        let future = peripheral.connect(10, timeoutRetries: ConfigStore.getMaximumReconnections(), connectionTimeout: Double(ConfigStore.getPeripheralConnectionTimeout()))
        future.onSuccess { (peripheral, connectionEvent) in
            switch connectionEvent {
            case .Connect:
                BCLogger.debug("Connected")
                Notify.withMessage("Connected peripheral: '\(peripheral.name)'")
                self.updateWhenActive()
            case .Timeout:

    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.updatePeripheralConnectionsSwitch = true
        self.stopPollingRSSIForPeripherals()
        NSNotificationCenter.defaultCenter().addObserver(self, selector:"didBecomeActive", name:BlueCapNotification.didBecomeActive, object:nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector:"didResignActive", name:BlueCapNotification.didResignActive, object:nil)
