             resumeReading()
         }
         
-        captureSession = AVCaptureSession()
-        
-        guard let captureSession = captureSession else {
+        self.captureSession = AVCaptureSession()
+        
+        guard let captureSession = self.captureSession else {
             return
         }
         

    public override func layoutSubviews() {
        super.layoutSubviews()
        videoPreviewLayer?.frame = self.bounds
    }
    
    deinit {

        let input = try AVCaptureDeviceInput(device: captureDevice)
        captureSession.addInput(input)
        
        captureSession.addOutput(self.captureMetadataOutput)
        self.captureMetadataOutput.metadataObjectTypes = codeTypes
        
        self.videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
        self.videoPreviewLayer?.videoGravity = .resizeAspectFill
        self.videoPreviewLayer?.frame = self.layer.bounds
        self.layer.addSublayer(self.videoPreviewLayer!)
        
        self.isScanning = true
        
        captureSession.startRunning()
        self.captureMetadataOutput.rectOfInterest = videoPreviewLayer!.metadataOutputRectConverted(fromLayerRect: scanRect)
        
    }
    
    @objc public func stopReading() {
