     func stopReading(_ command: CDVInvokedUrlCommand) {
         //stop camera
         captureSession?.stopRunning()
-        cameraPreview.videoPreviewLayer?.removeFromSuperlayer()
+        cameraPreview.removePreviewLayer()
         cameraPreview.videoPreviewLayer = nil
         self.barcodeReadCallback = nil
         let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "Camera Stopped")

    var width:CGFloat = 0.0
    var height:CGFloat = 0.0
    
    func startReading(_ command: CDVInvokedUrlCommand) {
        cameraPreview = CameraPreview();
        let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)

        do {

            if metadataObj.stringValue != nil {
                if (self.barcodeReadCallback != nil) {
                    let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: metadataObj.stringValue)
                    pluginResult!.setKeepCallbackAs(true)
                    commandDelegate!.send(pluginResult, callbackId:self.barcodeReadCallback)
                }
            }
