     cell.tag = name.hashValue
     URLRequest.requestFor(path: "https://robohash.org/\(name)")
       .then {(request) -> Promise<Data> in
-          self.session.fetchData(from: request)
+        self.session.fetchData(from: request)
       }
       .then { (data) -> UIImage in
         guard let image = UIImage(data: data) else {

    tableView.endUpdates()
  }
  
  
  
  fileprivate func showError(message: String) {
    let alert = UIAlertController(title: "Network connection required!", message: message, preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Ok", style: .cancel, handler: nil))
    self.present(alert, animated: true, completion: nil)
  }
  
  func oldReload() {
    let request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/users")!)
    session.dataTask(with: request) { (data, response, error) in
      self.tableView.refreshControl?.endRefreshing()
      if let error = error {
        self.showError(message: error.localizedDescription)
        return
      }
      
      let httpResponse = response as! HTTPURLResponse
      
      guard (200...299).contains( httpResponse.statusCode) else {
        self.showError(message: "Code: \(httpResponse.statusCode)")
        return
      }
      
      guard let data = data else {
        self.showError(message: "Data is Empty!")
        return
      }
      
      let decoder = JSONDecoder()
      do {
        let users =  try decoder.decode([User].self, from: data)
        self.users = users
        DispatchQueue.main.async {
          self.tableView.reloadData()
        }
      } catch {
        self.showError(message: error.localizedDescription)
      }
      
    }.resume()
  }
  
  func reloadData() {
    self.tableView.refreshControl?.beginRefreshing()
    resetUsers()
//    self.oldReload()
    URLRequest.requestFor(path: "https://jsonplaceholder.typicode.com/users")
      .then {(request) -> Promise<Data> in
        return self.session.fetchData(from: request)
      }
      .then { (data) -> [User] in
        let decoder = JSONDecoder()
        return try decoder.decode([User].self, from: data)
      }
      .onComplete { (_) in
        self.tableView.refreshControl?.endRefreshing()

  }
  
  @IBAction func pullToRefreshAction(_ sender: Any) {
    reloadData(delay: 2.0, errorSimulationCounter: 5)
//    oldReload()
//    reloadData()
  }
  
  func resetUsers() {
