         
         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)
+        if mode == .Present {
+            headerToFrame = headerTo.superview!.convertRect(headerTo.frame, toView: nil)
+            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
+        headerIntermediate.frame = mode == .Present ? headerFromFrame : headerToFrame
         
-        if self.transitionMode == .Present {
+        if mode == .Present {
             toView.transform = offScreenBottom
-            
             container.addSubview(fromView)
             container.addSubview(toView)
             container.addSubview(headerIntermediate)

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

                toView.alpha = 1.0
                headerIntermediate.frame = self.headerFromFrame
            }
        }, completion: { finished in
            headerIntermediate.removeFromSuperview()
            headerTo.alpha = 1
            headerFrom.alpha = 1
            if transitionContext.transitionWasCancelled() {
                transitionContext.completeTransition(false)
            } else {
                transitionContext.completeTransition(true)
            }
        })
        
    }
    
}

extension MCMHeaderAnimated: UIViewControllerTransitioningDelegate {
    
    public func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        mode = .Present
        return self
    }
    
    public func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        mode = .Dismiss
        return self
    }
    
    public func interactionControllerForDismissal(animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return interactive ? self : nil
    }
    
}

private extension UIViewController {
    
    func topMostViewController() -> UIViewController {
        if let navigation = self as? UINavigationController {
            if let visibleViewController = navigation.topViewController {
                return visibleViewController.topMostViewController()
            }
        }
        if let tab = self as? UITabBarController {
            if let selectedViewController = tab.selectedViewController {
                return selectedViewController.topMostViewController()
            }
        }
        return self
    }
    
}
