                        forCellReuseIdentifier: FriendCell.identifier)
     tableView.allowsMultipleSelection = true
   }
+
+  func cancelTapped() {
+    self.dismiss(animated: true, completion: nil)
+  }
+
+  func doneTapped() {
+    self.dismiss(animated: true, completion: nil)
+  }
 }
 
 extension FriendPickerViewController : UITableViewDataSource {
   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
       -> UITableViewCell {
     guard
-      let cellInfo = dataSource.cells[safe: indexPath.row] as? FriendCellInfo,
+        let key = dataSource.sortedFriends.keys.sorted()[safe: indexPath.section],
+      let contacts = dataSource.sortedFriends[key],
+      let contact = contacts[safe: indexPath.row],
       let cell =
-          tableView.dequeueReusableCell(withIdentifier: cellInfo.cellIdentifier,
+          tableView.dequeueReusableCell(withIdentifier: FriendCell.identifier,
                                         for: indexPath)
               as? ConfigurableTableViewCell
     else {
       return UITableViewCell()
     }
 
+    let cellInfo = dataSource.cells.filter { (ci) in
+      return (ci as! FriendCellInfo).fbid == contact
+    }.first! as! FriendCellInfo
     cell.configure(cellInfo: cellInfo)
     cell.accessoryType =
         dataSource.selectedFriends.contains(cellInfo.fbid) ? .checkmark : .none

        self.cells.append(FriendCellInfo(fbid: friend.fbid,
                                         name: friend.display_name,
                                         picture: friend.picture_url))
        onMain {
          completion()
        }

  }

  func sectionIndexTitles(for tableView: UITableView) -> [String]? {
    return dataSource.sortedFriends.keys.sorted()
  }
}

extension FriendPickerViewController : UITableViewDelegate {
  func numberOfSections(in tableView: UITableView) -> Int {
    return dataSource.sortedFriends.keys.count
  }

  func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return dataSource.sortedFriends.keys.sorted()[section]
  }

  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)
      -> Int {
    let key = dataSource.sortedFriends.keys.sorted()[section]
    return (dataSource.sortedFriends[key]?.count)!
  }

  func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell,
                 forRowAt indexPath: IndexPath) {
    let key = dataSource.sortedFriends.keys.sorted()[safe: indexPath.section]
    let contacts = dataSource.sortedFriends[key!]
    let contact = contacts?[safe: indexPath.row]
    let cellInfo = dataSource.cells.filter { (ci) in
      return (ci as! FriendCellInfo).fbid == contact
    }.first! as! FriendCellInfo
    cell.accessoryType =
        dataSource.selectedFriends.contains(cellInfo.fbid) ? .checkmark : .none
  }
