         do {
             let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice
             try captureDevice?.lockForConfiguration()
+
+            zoomScale = max(1.0, min(beginZoomScale * scale, maxZoomScale))
             
-            zoomScale = max(1.0, min(beginZoomScale * scale, maxZoomScale))
             captureDevice?.videoZoomFactor = zoomScale
+
+            captureDevice?.unlockForConfiguration()
             
-            captureDevice?.unlockForConfiguration()
         } catch {
             print("Error locking configuration")
         }

    }
    
    private func _setupMaxZoomScale() {
        if cameraDevice == .Back {
            if let maxZoom = backCameraDevice?.activeFormat.videoMaxZoomFactor {
                beginZoomScale = CGFloat(1.0)
                maxZoomScale = maxZoom
            }
        }
        else {
            if let maxZoom = frontCameraDevice?.activeFormat.videoMaxZoomFactor {
                beginZoomScale = CGFloat(1.0)
                maxZoomScale = maxZoom
            }
        }
    }

    private func _checkIfCameraIsAvailable() -> CameraState {

            if cameraIsSetup {
                if cameraDevice != oldValue {
                    _updateCameraDevice(cameraDevice)
                    _setupMaxZoomScale()
                    _zoom(0)
                }
            }
        }
