 
         let possibleCameraInput: AnyObject?
         do {
-            possibleCameraInput = try AVCaptureDeviceInput(device: backCameraDevice)
+            possibleCameraInput = try AVCaptureDeviceInput(device: backCameraDevice!)
         } catch let error1 as NSError {
             error = error1
             possibleCameraInput = nil
         }
         let backCameraInput = possibleCameraInput as? AVCaptureDeviceInput
-        if captureSession.canAddInput(backCameraInput) {
-            captureSession.addInput(backCameraInput)
+        if captureSession.canAddInput(backCameraInput!) {
+            captureSession.addInput(backCameraInput!)
         }
 
         stillImageOutput = AVCaptureStillImageOutput()
-        if captureSession.canAddOutput(stillImageOutput) {
+        if captureSession.canAddOutput(stillImageOutput!) {
             stillImageOutput?.isHighResolutionStillImageOutputEnabled = true;
             stillImageOutput?.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG];
-            captureSession.addOutput(stillImageOutput)
-        }
-        captureSession.sessionPreset = AVCaptureSessionPresetPhoto
+            captureSession.addOutput(stillImageOutput!)
+        }
+        captureSession.sessionPreset = AVCaptureSession.Preset.photo
         setFlashModeToAuto(backCameraDevice!)
         beginSession()
     }

@objc protocol cameraDelegate{ func cameraFinished(_ controller: HappieCameraViewController) }

@objc(HappieCameraViewController) class HappieCameraViewController : UIViewController, AVCaptureFileOutputRecordingDelegate  {

    //MARK: Class Variables
    let captureSession = AVCaptureSession() //provides a UI context for capturing media

    }

    //MARK: Utility Functions
    func deviceWithMediaType(_ mediaType : AVMediaType, preferringPosition: AVCaptureDevice.Position) -> AVCaptureDevice{
        let devices : [AVCaptureDevice] = AVCaptureDevice.devices(for: mediaType)
        var captureDevice: AVCaptureDevice = devices.first as! AVCaptureDevice

        for device in devices{
            if((device as AnyObject).position == preferringPosition){
