     }
     
     // start half or full flip animation
-    private func flip(progress: Progress) {
+    private func flip(flipPosition: FlipPosition) {
         CATransaction.begin()
         CATransaction.setCompletionBlock({
-            self.flipComplete(progress)
+            self.flipComplete(flipPosition)
         })
         
         let transition = CATransition()
         
-        transition.startProgress = progress.rawValue
-        transition.endProgress = progress.rawValue + 0.5
+        transition.startProgress = flipPosition.rawValue
+        transition.endProgress = flipPosition.rawValue + 0.5
         transition.type = TRANSITION_TYPE
         transition.subtype = TRANSITION_SUBTYPE
         transition.duration = speed


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

    }
    
    // event is called after every half round
    private func flipComplete(flipPosition: FlipPosition) {
        if (!isFlipping) {
            return
        }
        
        // change image only after a full round
        if let imageView = self.imageView {
            if (flipPosition == .Full) {
                increaseCurrentIndex()
                imageView.image = self.images[currentIndex]
            }
        }
        
        if (currentIndex == stopIndex && isStopping && flipPosition == .Half) {
            stopFlipping(currentIndex)
        } else {
            self.flip(flipPosition == .Full ? .Half : .Full)
        }
    }
    
    // start infinite flipping
    func startFlipping() {
        if (isFlipping) {
            return
        }
        
        isStopping = false
        isFlipping = true
        completion = nil
        
        flip(.Full)
    }
    
    // stop flipping immediately
    func stopFlipping() {
        isFlipping = false
        isStopping = false
        
        mainView.layer.removeAllAnimations()
    }
    
    // stop flipping immediately and show image with index
    func stopFlipping(index: Int) {
        stopFlipping()
        
        if let imageView = self.imageView {
            imageView.image = self.images[index]
