         if let completion = self.completion {
             completion()
         }
-        
-        mainView.layer.removeAllAnimations()
+    }
+    
+    
+    // stop flipping as soon as image with index is reached
+    func stopFlipping(index: Int, completion: () -> Void) {
+        isStopping = true
+        stopIndex = index
+        self.completion = completion
     }
 }


class FlipCoinManager {
    
    private enum Progress: Float {
        case Full = 0.0
        case Half = 0.5
    }

    private var imageView: UIImageView?
    private var completion: (() -> Void)?
    
    private var isFlipping: Bool = false
    private var isStopping: Bool = false
    
    private var currentIndex: Int = 0
