             TSMessage.showNotificationWithTitle("Device is being flashed", subtitle: "Device is currently being flashed, please wait for the process to finish.", type: .Warning)
             
         }
-        else if self.devices[indexPath.row].connected
-        {
-            switch devices[indexPath.row].isRunningTinker()
-            {
-            case true :
-                
+        else if !device.connected
+        {
+            self.lastTappedNonTinkerDevice = nil
+            TSMessage.showNotificationWithTitle("Device offline", subtitle: "This device is offline, please turn it on and refresh in order to Tinker with it.", type: .Error)
+            
+        } else {
+            
+            
+            // heading
+            let optionMenu = UIAlertController(title: "Device selected", message: device.id, preferredStyle: .ActionSheet)
+            
+            
+            // 1
+            let tinkerAction = UIAlertAction(title: "Tinker", style: .Default, handler: {
+                (alert: UIAlertAction!) -> Void in
+                //                self.invokePhotonDeviceSetup()
                 self.selectedDevice = self.devices[indexPath.row]
                 self.performSegueWithIdentifier("tinker", sender: self)
-            default :
-                if let ntd = self.lastTappedNonTinkerDevice where self.devices[indexPath.row].id == ntd.id
+                
+            })
+            
+            // 2
+            let reflashAction = UIAlertAction(title: "Reflash Tinker", style: .Default, handler: {
+                (alert: UIAlertAction!) -> Void in
+                
+                switch (device.type)
                 {
-                    self.selectedDevice = self.devices[indexPath.row]
-                    self.performSegueWithIdentifier("tinker", sender: self)
-                }
-                else
-                {
-                    let device = self.devices[indexPath.row]
-                    self.lastTappedNonTinkerDevice = device
-                    NSTimer.scheduledTimerWithTimeInterval(10.0, target: self, selector: #selector(DeviceListViewController.resetLastTappedDevice(_:)), userInfo: nil, repeats: false)
-                    
-                    // TODO: add "not running tinker, do you want to flash?"
-                    TSMessage.showNotificationInViewController(self, title: "Device not running Tinker", subtitle: "Do you want to flash Tinker firmware to this device? Tap device again to Tinker with it anyway", image: UIImage(named: "imgQuestionWhite"), type: .Message, duration: -1, callback: { () -> Void in
-                        // callback for user dismiss by touching inside notification
-                        TSMessage.dismissActiveNotification()
-                        } , buttonTitle: " Flash ", buttonCallback: { () -> Void in
-                            self.lastTappedNonTinkerDevice = nil
+                case .Core:
+                    //                                        Mixpanel.sharedInstance().track("Tinker: Reflash Tinker",
+                    Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Core"])
+                    
+                    device.flashKnownApp("tinker", completion: { (error:NSError?) -> Void in
+                        if let e=error
+                        {
+                            TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
+                        }
+                        else
+                        {
+                            TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
+                            //                                                self.deviceIDsBeingFlashed[device.id] = defaultFlashingTime
+                            //                                                self.flashingTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "flashingTimerFunc:", userInfo: nil, repeats: true)
+                            device.isFlashing = true
+                            self.deviceIDflashingDict[device.id] = kDefaultCoreFlashingTime
+                            self.photonSelectionTableView.reloadData()
                             
-                            // TODO: duplicate code - fix
-                            switch (device.type)
+                        }
+                    })
+                    
+                case .Photon:
+                    Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Photon"])
+                    
+                    let bundle = NSBundle.mainBundle()
+                    let path = bundle.pathForResource("photon-tinker", ofType: "bin")
+                    //                                        var error:NSError?
+                    if let binary: NSData? = NSData.dataWithContentsOfMappedFile(path!) as? NSData // fix deprecation
+                    {
+                        let filesDict = ["tinker.bin" : binary!]
+                        device.flashFiles(filesDict, completion: { (error:NSError?) -> Void in
+                            if let e=error
                             {
-                            case .Core:
-                                //                                        Mixpanel.sharedInstance().track("Tinker: Reflash Tinker",
-                                Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Core"])
+                                TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
+                            }
+                            else
+                            {
+                                TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
+                                device.isFlashing = true
+                                self.deviceIDflashingDict[device.id] = kDefaultPhotonFlashingTime
+                                self.photonSelectionTableView.reloadData()
                                 
-                                device.flashKnownApp("tinker", completion: { (error:NSError?) -> Void in
-                                    if let e=error
-                                    {
-                                        TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
-                                    }
-                                    else
-                                    {
-                                        TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
-                                        //                                                self.deviceIDsBeingFlashed[device.id] = defaultFlashingTime
-                                        //                                                self.flashingTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "flashingTimerFunc:", userInfo: nil, repeats: true)
-                                        device.isFlashing = true
-                                        self.deviceIDflashingDict[device.id] = kDefaultCoreFlashingTime
-                                        self.photonSelectionTableView.reloadData()
-                                        
-                                    }
-                                })
-                                
-                            case .Photon:
-                                Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Photon"])
-                                
-                                let bundle = NSBundle.mainBundle()
-                                let path = bundle.pathForResource("photon-tinker", ofType: "bin")
-                                //                                        var error:NSError?
-                                if let binary: NSData? = NSData.dataWithContentsOfMappedFile(path!) as? NSData // fix deprecation
+                            }
+                        })
+                        
+                    }
+                case .Electron:
+                    Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Electron"])
+                    // TODO: support flashing tinker to Electron
+                    //                                TSMessage.showNotificationWithTitle("Not supported", subtitle: "Operation not supported yet, coming soon.", type: .Warning)
+                    
+                    
+                    // heading
+                    let areYouSureAlert = UIAlertController(title: "Flashing Tinker to Electron", message: "Flashing Tinker to Electron will consume X KB of data from your data plan, are you sure you want to continue?", preferredStyle: .Alert)
+                    
+                    let noAction = UIAlertAction(title: "No", style: .Cancel, handler: {
+                        (alert: UIAlertAction!) -> Void in
+                    })
+                    
+                    let yesAction = UIAlertAction(title: "Yes", style: .Default, handler: {
+                        (alert: UIAlertAction!) -> Void in
+                        // check if this works otherwise put binary
+                        let bundle = NSBundle.mainBundle()
+                        let path = bundle.pathForResource("electron-tinker", ofType: "bin")
+                        //                                        var error:NSError?
+                        if let binary: NSData? = NSData.dataWithContentsOfMappedFile(path!) as? NSData // fix deprecation
+                        {
+                            let filesDict = ["tinker.bin" : binary!]
+                            device.flashFiles(filesDict, completion: { (error:NSError?) -> Void in
+                                if let e=error
                                 {
-                                    let filesDict = ["tinker.bin" : binary!]
-                                    device.flashFiles(filesDict, completion: { (error:NSError?) -> Void in
-                                        if let e=error
-                                        {
-                                            TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
-                                        }
-                                        else
-                                        {
-                                            TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your device is being flashed with Tinker firmware...", type: .Success)
-                                            //                                                    self.deviceIDsBeingFlashed[device.id] = defaultFlashingTime
-                                            //                                                    self.flashingTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "flashingTimerFunc:", userInfo: nil, repeats: true)
-                                            device.isFlashing = true
-                                            self.deviceIDflashingDict[device.id] = kDefaultPhotonFlashingTime
-                                            self.photonSelectionTableView.reloadData()
-                                            
-                                        }
-                                    })
+                                    TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
+                                }
+                                else
+                                {
+                                    TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while Electron is being flashed with Tinker firmware...", type: .Success)
+                                    device.isFlashing = true
+                                    self.deviceIDflashingDict[device.id] = kDefaultPhotonFlashingTime
+                                    self.photonSelectionTableView.reloadData()
                                     
                                 }
-                            case .Electron:
-                                Mixpanel.sharedInstance().track("Tinker: Reflash Tinker", properties: ["device":"Electron"])
-                                // TODO: support flashing tinker to Electron
-//                                TSMessage.showNotificationWithTitle("Not supported", subtitle: "Operation not supported yet, coming soon.", type: .Warning)
-                                
-                                
-                                // heading
-                                let optionMenu = UIAlertController(title: "Flashing Tinker to Electron", message: "Flashing Tinker to Electron will consume X KB of data from your data plan, are you sure you want to continue?", preferredStyle: .Alert)
-                                
-                                
-                                let yesAction = UIAlertAction(title: "Yes", style: .Default, handler: {
-                                    (alert: UIAlertAction!) -> Void in
-                                    // check if this works otherwise put binary
-                                    device.flashKnownApp("tinker", completion: { (error:NSError?) -> Void in
-                                        if let e=error
-                                        {
-                                            TSMessage.showNotificationWithTitle("Flashing error", subtitle: "Error flashing device: \(e.localizedDescription)", type: .Error)
-                                        }
-                                        else
-                                        {
-                                            TSMessage.showNotificationWithTitle("Flashing successful", subtitle: "Please wait while your Electron is being flashed with Tinker firmware...", type: .Success)
-                                            device.isFlashing = true
-                                            self.deviceIDflashingDict[device.id] = kDefaultElectronFlashingTime
-                                            self.photonSelectionTableView.reloadData()
-                                            
-                                        }
-                                    })
-
-                                    
-                                })
-                                
-                                                              // cancel
-                                let cancelAction = UIAlertAction(title: "No", style: .Cancel, handler: {
-                                    (alert: UIAlertAction!) -> Void in
-                                })
-                                
-                                
-                                // 4
-                                optionMenu.addAction(yesAction)
-                                optionMenu.addAction(cancelAction)
-                                
-                                // 5
-                                self.presentViewController(optionMenu, animated: true, completion: nil)
-                                
-                                
-                            }
-                        }, atPosition: .Top, canBeDismissedByUser: true)
-                    
-                    
-                    //TSMessage.showNotificationWithTitle("Device not running Tinker", subtitle: "This device firmware is not Tinker, tap it again if you want to Tinker with it anyway.", type: .Warning)
-                    
+                            })
+                            
+                        }
+                    })
+                    optionMenu.addAction(yesAction)
+                    optionMenu.addAction(noAction)
+                    self.presentViewController(areYouSureAlert, animated: true, completion: nil)
                 }
-            }
-            
-        }
-        else
-        {
-            self.lastTappedNonTinkerDevice = nil
-            TSMessage.showNotificationWithTitle("Device offline", subtitle: "This device is offline, please turn it on and refresh in order to Tinker with it.", type: .Error)
+                
+            })
+            
+            // 3
+            /*
+             let functionsAction = UIAlertAction(title: "Functions", style: .Default, handler: {
+             (alert: UIAlertAction!) -> Void in
+             //                self.showSparkCoreAppPopUp()
+             })
+             
+             let variablesAction = UIAlertAction(title: "Variables", style: .Default, handler: {
+             (alert: UIAlertAction!) -> Void in
+             //                self.showSparkCoreAppPopUp()
+             })
+             
+             let eventsAction = UIAlertAction(title: "Events", style: .Default, handler: {
+             (alert: UIAlertAction!) -> Void in
+             //                self.showSparkCoreAppPopUp()
+             })
+             */
+            
+            let infoAction = UIAlertAction(title: "More info", style: .Default) {
+                (alert: UIAlertAction!) -> Void in
+                //                self.showSparkCoreAppPopUp()
+            }
+            
+            // cancel
+            let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
+                (alert: UIAlertAction!) -> Void in
+            })
+            
+            
+            // 4
+            
+            if device.isRunningTinker() {
+                optionMenu.addAction(tinkerAction)
+            } else {
+                optionMenu.addAction(reflashAction)
+            }
+            //            optionMenu.addAction(functionsAction)
+            //            optionMenu.addAction(variablesAction)
+            //            optionMenu.addAction(eventsAction)
+            optionMenu.addAction(infoAction)
+            optionMenu.addAction(cancelAction)
+            
+            
+            // 5
+            self.presentViewController(optionMenu, animated: true, completion: nil)
+            
         }
     }
     

        return masterCell!
    }
    

    
    
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

            case .Core:
                cell.deviceImageView.image = UIImage(named: "imgCore")
                cell.deviceTypeLabel.text = "Core"
                
            case .Electron:
                cell.deviceImageView.image = UIImage(named: "imgElectron")
                cell.deviceTypeLabel.text = "Electron"
                
            case .Photon: // .Photon
                fallthrough
            default:
                cell.deviceImageView.image = UIImage(named: "imgPhoton")
                cell.deviceTypeLabel.text = "Photon"
                
            }
            
            cell.deviceIDLabel.text = devices[indexPath.row].id.uppercaseString
            
            let online = self.devices[indexPath.row].connected
