 }
 
 extension UIView {
-    func pb_takeSnapshot(frame: CGRect) -> UIImage {
+    func pb_takeSnapshot(frame: CGRect) -> UIImage? {
         UIGraphicsBeginImageContextWithOptions(frame.size, false, 0.0);
         
         let context = UIGraphicsGetCurrentContext();
         CGContextTranslateCTM(context, frame.origin.x * -1, frame.origin.y * -1);
         
-        self.layer.renderInContext(UIGraphicsGetCurrentContext()!);
+        guard let currentContext = UIGraphicsGetCurrentContext() else {
+            return nil
+        }
+        
+        self.layer.renderInContext(currentContext);
         let image = UIGraphicsGetImageFromCurrentImageContext();
         UIGraphicsEndImageContext();
 

    }
    
    func configureAnimationItems(animationType: AnimationType) {
        if animationType == .Open {
            for view in animationView!.subviews.filter({$0 is RotatedView}) {
                view.alpha = 0;
            }
        } else { // close
            for view: RotatedView in animationView!.subviews.filter({$0 is RotatedView}) as! [RotatedView] {
                if animationType == .Open {
                    view.alpha = 0
                } else {

        var hidden = true
        configureAnimationItems(.Close)
        for var index = 0; index < animationItemViews?.count; index++ {

            guard let animatedView = animationItemViews?.reverse()[index] else {
                continue
            }
            
            animatedView.foldingAnimation(timing, from: from, to: to, duration: durations[index], delay: delay, hidden: hidden)
            
            to = to == 0.0 ? CGFloat(M_PI / 2) : 0.0;
            from = from == 0.0 ? CGFloat(-M_PI / 2) : 0.0;
