         super.init()
     }
     
+    deinit {
+//        photosManager.stopCachingImagesForAllAssets()
+    }
+    
     func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
-        return assets.count
+        if let assets = assets {
+            return assets.count
+        }
+        
+        return 0
     }
     
     func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

            NSSortDescriptor(key: "creationDate", ascending: false)
        ]
        
        if let results = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions) {
            var assets: [PHAsset] = []
            results.enumerateObjectsUsingBlock { (object, idx, _) in
                if let asset = object as? PHAsset {
                    assets.append(asset)
                }
            }
            

            photosManager.cancelImageRequest(PHImageRequestID(cell.tag))
        }
        
        if let assets = assets {
            let asset = assets[indexPath.row]
            cell.tag = Int(photosManager.requestImageForAsset(asset, targetSize: imageSize, contentMode: imageContentMode, options: nil) { (result, _) in
                cell.imageView.image = result
            })
        }
        
        return cell
    }
    
    private func stopCaching() {
//        if let assets = assets {
//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
//                self.photosManager.stopCachingImagesForAssets(assets, targetSize: self.imageSize, contentMode: self.imageContentMode, options: nil)
//            }
//        }
    }
    
    private func startCaching() {
//        if let assets = assets {
//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
//                self.photosManager.startCachingImagesForAssets(assets, targetSize: self.imageSize, contentMode: self.imageContentMode, options: nil)
//            }
//        }
    }
}
