         do{
             try device.lockForConfiguration();
             if(backCameraDevice!.hasFlash){
-                if(backCameraDevice!.isFlashModeSupported(AVCaptureFlashMode.auto)){
-                    device.flashMode = AVCaptureFlashMode.auto;
+                if(backCameraDevice!.isFlashModeSupported(AVCaptureDevice.FlashMode.auto)){
+                    device.flashMode = AVCaptureDevice.FlashMode.auto;
                     let image = UIImage(named: "camera_flash_auto.png") as UIImage!
                     flashUIButton.setImage(image, for: UIControlState())
                 }
-                if(backCameraDevice!.isTorchModeSupported(AVCaptureTorchMode.off)){
-                    device.torchMode = AVCaptureTorchMode.off;
+                if(backCameraDevice!.isTorchModeSupported(AVCaptureDevice.TorchMode.off)){
+                    device.torchMode = AVCaptureDevice.TorchMode.off;
                 }
             }else{
                 let image = UIImage(named: "camera_flash_off.png") as UIImage!


        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 = AVCaptureSessionPresetPhoto
        setFlashModeToAuto(backCameraDevice!)
        beginSession()
    }

        if(canTakePhoto){
            HappieCameraJSON.incrementProcessingCount();
            canTakePhoto = false;
            let connection = stillImageOutput?.connection(with: AVMediaType.video)

            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;
