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


        let possibleCameraInput: AnyObject?
        do {
            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!)
        }

        stillImageOutput = AVCaptureStillImageOutput()
        if captureSession.canAddOutput(stillImageOutput!) {
            stillImageOutput?.isHighResolutionStillImageOutputEnabled = true;
            stillImageOutput?.outputSettings = [AVVideoCodecKey : AVVideoCodecJPEG];
            captureSession.addOutput(stillImageOutput!)
        }
        captureSession.sessionPreset = AVCaptureSession.Preset.photo
        setFlashModeToAuto(backCameraDevice!)
        beginSession()
    }

        if(canTakePhoto){
            HappieCameraJSON.incrementProcessingCount();
            canTakePhoto = false;
            let connection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo)

            stillImageOutput?.captureStillImageAsynchronously(from: connection) { imageBuffer, error in
                if((imageBuffer) != nil){
                    let imageData: Data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageBuffer)
                    let UIImageFromData = UIImage(data: imageData)

                    var  orient = UIImageOrientation.right;
