     
     override func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell {
         let cell = tableView.dequeueReusableCellWithIdentifier(MainStoryboard.peripheralCell, forIndexPath: indexPath) as! PeripheralCell
-        let peripheral = Singletons.centralManager.peripherals[indexPath.row]
+        let peripheral: BCPeripheral
+        if ConfigStore.getPeripheralSortOrder() == .DiscoveryDate {
+             peripheral = Singletons.centralManager.peripherals[indexPath.row]
+        } else {
+            peripheral = self.peripheralsSortedByRSSI[indexPath.row]
+        }
         cell.nameLabel.text = peripheral.name
         cell.accessoryType = .None
         if peripheral.state == .Connected {

                peripheral.reconnect()
                self.updateWhenActive()
            case .Disconnect:
                BCLogger.debug("Disconnect")
                Notify.withMessage("Disconnected peripheral: '\(peripheral.name)'")
                peripheral.reconnect()
                NSNotificationCenter.defaultCenter().postNotificationName(BlueCapNotification.peripheralDisconnected, object:peripheral)
                self.updateWhenActive()
            case .ForceDisconnect:
                BCLogger.debug("ForcedDisconnect")
                Notify.withMessage("Force disconnection of: '\(peripheral.name)'")
                NSNotificationCenter.defaultCenter().postNotificationName(BlueCapNotification.peripheralDisconnected, object:peripheral)
                self.updateWhenActive()
            case .Failed:
                BCLogger.debug("Failed")
                Notify.withMessage("Connection failed peripheral: '\(peripheral.name)'")
            case .GiveUp:
                BCLogger.debug("GiveUp: '\(peripheral.name)'")

    }

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