         return subLayer
     }
     
+    private func removeImageLayer(image: UIImage?) {
+        DispatchQueue.main.async {
+            // avoid redundant layer when focus on faces for the image of cell specified in UITableView
+            self.imageLayer().removeFromSuperlayer()
+            self.image = image
+        }
+    }
+    
     private func sublayer() -> CALayer? {
         if let sublayers = layer.sublayers {
             for layer in sublayers {

            if features.count > 0 {
                print("found \(features.count) faces")
                let imgSize = CGSize(width: Double(image.cgImage!.width), height: (Double(image.cgImage!.height)))
                self.applyFaceDetection(for: features, size: imgSize, cgImage: image.cgImage!)
            } else {
                print("No faces found")
                DispatchQueue.main.async {
                    self.imageLayer().removeFromSuperlayer()
                }
            }
            DispatchQueue.main.sync {
                self.image = image
            }
        }
    }
    
    private func applyFaceDetection(for features: [AnyObject], size: CGSize, cgImage: CGImage) {
        var rect = features[0].bounds!
        rect.origin.y = size.height - rect.origin.y - rect.size.height
        var rightBorder = Double(rect.origin.x + rect.size.width)

    
    public func set(image: UIImage?, focusOnFaces: Bool) {
        guard focusOnFaces == true else {
            self.removeImageLayer(image: image)
            return
        }
        setImageAndFocusOnFaces(image: image)
