 extension UIImage {
     
     class func animatedImageWithData(data: NSData) -> UIImage? {
-        let source = CGImageSourceCreateWithData(data, nil)
-        let image = UIImage.animatedImageWithSource(source)
-        
-        return image
+        guard let source = CGImageSourceCreateWithData(data, nil) else { return nil }
+
+        return UIImage.animatedImageWithSource(source)
     }
     
     class func delayForImageAtIndex(index: Int, source: CGImageSource!)

        var frame: UIImage
        var frameCount: Int
        for i in 0..<count {
            frame = UIImage(CGImage: images[Int(i)])!
            frameCount = Int(delays[Int(i)] / gcd)
            
            for j in 0..<frameCount {
                frames.append(frame)
            }
        }

        
        // Swap for modulo
        if a < b {
            let c = a
            a = b
            b = c
        }
