 public protocol MCMHeaderAnimatedDelegate {
     
     func headerView() -> UIView
-    
     func headerCopy(subview: UIView) -> UIView
     
 }
 
 public class MCMHeaderAnimated: UIPercentDrivenInteractiveTransition {
     
-    public var transitionMode: TransitionMode = .Present
-    public var transitionInteracted: Bool = false
-    
-    private var headerFromFrame: CGRect! = nil
-    private var headerToFrame: CGRect! = nil
-    
-    private var enterPanGesture: UIPanGestureRecognizer!
-    public var destinationViewController: UIViewController! {
-        didSet {
-            self.enterPanGesture = UIPanGestureRecognizer()
-            self.enterPanGesture.addTarget(self, action: "handleOnstagePan:")
-            self.destinationViewController.view.addGestureRecognizer(self.enterPanGesture)
-            self.transitionInteracted = true
-        }
-    }
-    
     public enum TransitionMode: Int {
         case Present, Dismiss
     }
     
-    func handleOnstagePan(pan: UIPanGestureRecognizer){
-        
-        let translation = pan.translationInView(pan.view!)
-        let d =  translation.y / CGRectGetHeight(pan.view!.bounds) * 1.5
-        
-        switch (pan.state) {
-            case UIGestureRecognizerState.Began:
+    public var mode: TransitionMode = .Present
+    
+    private var interactive = false
+    
+    private let panGesture = UIPanGestureRecognizer()
+    
+    public var destinationViewController: UIViewController? {
+        didSet {
+            panGesture.addTarget(self, action: "handlePan:")
+            destinationViewController?.view.addGestureRecognizer(panGesture)
+        }
+    }
+    
+    private var headerToFrame = CGRect()
+    private var headerFromFrame = CGRect()
+    
+    // MARK:
+    
+    func handlePan(recognizer: UIPanGestureRecognizer) {
+        if let
+            destinationViewController = destinationViewController,
+            view = recognizer.view
+        {
+            let translation = recognizer.translationInView(view)
+            let delta = translation.y / view.bounds.height * 1.5
             
-                self.destinationViewController.dismissViewControllerAnimated(true, completion: nil)
-            break
-            case .Changed:
-                
-                self.updateInteractiveTransition(d)
-            break
-            
-            default: // .Ended, .Cancelled, .Failed ...
-                
-                self.finishInteractiveTransition()
+            switch (recognizer.state) {
+                case .Began:
+                    interactive = true
+                    destinationViewController.dismissViewControllerAnimated(true, completion: nil)
+                case .Changed:
+                    self.updateInteractiveTransition(delta)
+                default:
+                    interactive = false
+                    if delta > 0.5 {
+                        self.finishInteractiveTransition()
+                    } else {
+                        self.cancelInteractiveTransition()
+                    }
+            }
         }
     }
     
 }
 
 // MARK: - UIViewControllerAnimatedTransitioning
-
 extension MCMHeaderAnimated: UIViewControllerAnimatedTransitioning {
     
     public func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval {

        
        let alpha: CGFloat = 0.1
        let offScreenBottom = CGAffineTransformMakeTranslation(0, container.frame.height)

        // Prepare header
        let headerTo = (toController as! MCMHeaderAnimatedDelegate).headerView()
        let headerFrom = (fromController as! MCMHeaderAnimatedDelegate).headerView()
        
        if self.transitionMode == .Present {
            self.headerToFrame = headerTo.superview!.convertRect(headerTo.frame, toView: nil)
            self.headerFromFrame = headerFrom.superview!.convertRect(headerFrom.frame, toView: nil)
        }
        
        headerFrom.alpha = 0
        headerTo.alpha = 0
        let headerIntermediate = (fromController as! MCMHeaderAnimatedDelegate).headerCopy(headerFrom)
        headerIntermediate.frame = self.transitionMode == .Present ? self.headerFromFrame : self.headerToFrame
        
        if self.transitionMode == .Present {
            toView.transform = offScreenBottom
            
            container.addSubview(fromView)
            container.addSubview(toView)
            container.addSubview(headerIntermediate)

            container.addSubview(headerIntermediate)
        }
        
        UIView.animateWithDuration(duration, delay: 0.0, options: nil, animations: {
            if self.mode == .Present {
                fromView.alpha = alpha
                toView.transform = CGAffineTransformIdentity
                headerIntermediate.frame = self.headerToFrame
