 	var photos = [PhotoData]()
 	var images = [UIImage]()
 	
-	
     override func viewDidLoad() {
         super.viewDidLoad()
 
-        // Uncomment the following line to preserve selection between presentations
-        // self.clearsSelectionOnViewWillAppear = false
-
-        // Register cell classes
         self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
-
-        // Do any additional setup after loading the view.
-    }
-
-    override func didReceiveMemoryWarning() {
-        super.didReceiveMemoryWarning()
-        // Dispose of any resources that can be recreated.
+		
+		do { try refresh() }
+		catch { print(error.localizedDescription) }
     }
 	
 	func refresh() throws {
-		
+		let task = createPhotoDownloadTask()
+		task.resume()
+	}
+	
+	private func createPhotoDownloadTask() -> URLSessionDownloadTask {
 		let handler = { (location: URL?, response: URLResponse?, error: Error?) in
 			do {
 				if let error = error { throw NetworkError.responseFailed(reason: "Received error: ↴\n\(error.localizedDescription)") }

		let photosRequest = URLRequest(url: photoBankURL)
		let task = session.downloadTask(with: photosRequest, completionHandler: handler)
		
		task.resume()
	}

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */

    // MARK: UICollectionViewDataSource

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return photos.count


    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
		
		if let photoCell = cell as? PhotoCell {
			photoCell.photo = photos[indexPath.row]
			return photoCell
		}
    
        return cell
    }

    // MARK: UICollectionViewDelegate

    override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
        return true
    }

	override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
		let photo = photos[indexPath.row]
		presentDetailView(for: photo)
	}
	
	fileprivate func presentDetailView(for photo: PhotoData) {
		let detailViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: L10n.photoDetailViewController)
		detailViewController.photo = photo
		
		present(detailViewController, animated: true, completion: nil)

	}
}
