         prevLayer = AVCaptureVideoPreviewLayer(session: session)
         prevLayer.frame = view.bounds
         prevLayer.videoGravity = .resizeAspectFill
-        view.layer.addSublayer(prevLayer)
+        view.layer.insertSublayer(prevLayer, at: 0)
 
         session.startRunning()
-
-
-        view.bringSubviewToFront(label)
-        view.bringSubviewToFront(circleView)
-        view.bringSubviewToFront(overlayButton)
-        view.bringSubviewToFront(overlayImageView)
-        view.bringSubviewToFront(cancelButton)
     }
 
     override func viewWillAppear(_ animated: Bool) {

        }
        self.view.addSubview(label)



        overlayImageView = UIImageView(image: UIImage(named: "ImgOverlayGraphic"))
        overlayImageView.frame = CGRect(x: 30, y: 150, width: view.bounds.size.width - 60, height: view.bounds.size.height - 300)
        overlayImageView.image = overlayImageView.image?.withRenderingMode(.alwaysTemplate)
        overlayImageView.tintColor = UIColor.white
        view.addSubview(overlayImageView)


        overlayButton = UIButton(type: .custom)
        overlayButton.setImage(UIImage(named: "ImgFlashlight"), for: .normal)
        overlayButton.frame = CGRect(x: 30, y: 30, width: 48, height: 48)
        overlayButton.tintColor = UIColor.white
        overlayButton.addTarget(self, action: #selector(toggleTorchButton), for: .touchUpInside)
        view.addSubview(overlayButton)


        cancelButton = UIButton(type: .system)
        cancelButton.setTitle("Cancel", for: .normal)
        cancelButton.frame = CGRect(x: view.bounds.size.width - 60, y: view.bounds.size.height - 44, width: 60, height: 48)
        cancelButton.addTarget(self, action: #selector(cancelScan), for: .touchUpInside)
        view.addSubview(cancelButton)

        circleView = UIView(frame: CGRect(x: 22, y: 24, width: 64, height: 64))
        circleView.alpha = 0.5
        circleView.layer.cornerRadius = 32
        circleView.backgroundColor = UIColor.gray
        view.addSubview(circleView)

        session = AVCaptureSession()
        device = AVCaptureDevice.default(for: .video)

    var input: AVCaptureDeviceInput?

    var label: UILabel!
    var labelBackground: UIView!

    var overlayImageView: UIImageView!

    var flashlightButton: UIButton!
    var flashlightButtonBackground: UIView!

    var cancelButtonBackground: UIView!
    var cancelButton: UIButton!

    var eSeriesSetup: Bool!

