 
         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 = AVCaptureSession.Preset.photo
+            captureSession.addOutput(stillImageOutput)
+        }
+        captureSession.sessionPreset = AVCaptureSessionPresetPhoto
         setFlashModeToAuto(backCameraDevice!)
         beginSession()
     }

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

@objc(HappieCameraViewController) class HappieCameraViewController : UIViewController, AVCaptureFileOutputRecordingDelegate  {
    func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {

    }


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


        previewLayer?.frame = CGRect(x: 0, y: 0, width: width,height: height)
        previewLayer?.bounds = CGRect(x: 0, y: 0,width: width,height: height)
        previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill;
        
        previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation(rawValue: orientation.rawValue)!;
        camPreview.layer.addSublayer(previewLayer!)

        captureSession.startRunning()
