                     if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.Off)){
                         device.torchMode = AVCaptureTorchMode.Off;
                     }
-                }else{
-                    let image = UIImage(named: "camera_flash_off.png") as UIImage!
-                    flashUIButton.setImage(image, forState: .Normal)
-                    flashUIButton.hidden = true;
-                }
-                flashState = 2
-
-
+                    flashState = 2
+                }
+                else if(flashState == 2){
+                    if(backCameraDevice!.isFlashModeSupported(AVCaptureFlashMode.Off)){
+                        device.flashMode = AVCaptureFlashMode.Off;
+                        let image = UIImage(named: "camera_flash_on.png") as UIImage!
+                        flashUIButton.setImage(image, forState: .Normal)
+                    }
+                    if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.On)){
+                        device.torchMode = AVCaptureTorchMode.On;
+                    }
+
+                    flashState = 0;
+                }
                 device.unlockForConfiguration()
-            }catch{
-                //TODO write error handling code at some point
-            }
-        }
-    
-    func toggleFlashMode(device:AVCaptureDevice){
-            do{
-                if(backCameraDevice!.hasFlash){
-                    try device.lockForConfiguration();
-
-                    if(flashState == 0){
-                        if(backCameraDevice!.isFlashModeSupported(AVCaptureFlashMode.Off)){
-                            device.flashMode = AVCaptureFlashMode.Off;
-                            let image = UIImage(named: "camera_flash_off.png") as UIImage!
-                            flashUIButton.setImage(image, forState: .Normal)
-                        }
-                        if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.Off)){
-                            device.torchMode = AVCaptureTorchMode.Off;
-                        }
-                        flashState = 1;
-                    }
-
-                    else if(flashState == 1){
-                        if(backCameraDevice!.isFlashModeSupported(AVCaptureFlashMode.Auto)){
-                            device.flashMode = AVCaptureFlashMode.Auto;
-                            let image = UIImage(named: "camera_flash_auto.png") as UIImage!
-                            flashUIButton.setImage(image, forState: .Normal)
-                        }
-                        if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.Off)){
-                            device.torchMode = AVCaptureTorchMode.Off;
-                        }
-                        flashState = 2
-                    }
-                    else if(flashState == 2){
-                        if(backCameraDevice!.isFlashModeSupported(AVCaptureFlashMode.Off)){
-                            device.flashMode = AVCaptureFlashMode.Off;
-                            let image = UIImage(named: "camera_flash_on.png") as UIImage!
-                            flashUIButton.setImage(image, forState: .Normal)
-                        }
-                        if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.On)){
-                            device.torchMode = AVCaptureTorchMode.On;
-                        }
-
-                        flashState = 0;
-                    }
-                    device.unlockForConfiguration()
-                }
-
-            }catch{
-                //TODO write error handling code at some point
-            }
-        }
-
+            }
+
+        }catch{
+            //TODO write error handling code at some point
+        }
+    }
     
     func generateFileName() -> String {
         let date = NSDate()

        }
        return captureDevice
    }
    
    func setFlashModeToAuto(device: AVCaptureDevice){
            do{
                try device.lockForConfiguration();
                if(backCameraDevice!.hasFlash){
                    if(backCameraDevice!.isFlashModeSupported(AVCaptureFlashMode.Auto)){
                        device.flashMode = AVCaptureFlashMode.Auto;
                        let image = UIImage(named: "camera_flash_auto.png") as UIImage!

                }
        })
    }

    // MARK: AVCaptureFileOutputRecordingDelegate Delegate Conformance
    func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
    }

    //MARK: Utility Functions
    func deviceWithMediaType(mediaType: NSString, preferringPosition: AVCaptureDevicePosition) -> AVCaptureDevice{
        let devices: NSArray = AVCaptureDevice.devicesWithMediaType(mediaType as String)
        var captureDevice: AVCaptureDevice = devices.firstObject as! AVCaptureDevice

        for device in devices{
            if(device.position == preferringPosition){
                captureDevice = device as! AVCaptureDevice
