         // Fill arrays
         for i in 0..<count {
             // Add image
-            images.append(CGImageSourceCreateImageAtIndex(source, i, nil))
+            if let image = CGImageSourceCreateImageAtIndex(source, i, nil) {
+                images.append(image)
+            }
             
             // At it's delay in cs
-            var delaySeconds = UIImage.delayForImageAtIndex(Int(i),
+            let delaySeconds = UIImage.delayForImageAtIndex(Int(i),
                 source: source)
             delays.append(Int(delaySeconds * 1000.0)) // Seconds to ms
         }

        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)
            }
        }

extension UIImage {
    
    class func animatedImageWithData(data: NSData) -> UIImage? {
        guard let source = CGImageSourceCreateWithData(data, nil) else { return nil }

        return UIImage.animatedImageWithSource(source)
    }
    
    class func delayForImageAtIndex(index: Int, source: CGImageSource!)
