     }
     
     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
-        let cell = tableView.dequeueReusableCell(withIdentifier: DKImageGroupCellIdentifier, for: indexPath) as! DKAssetGroupCell
-		
-        let assetGroup = getImageManager().groupDataManager.fetchGroupWithGroupId(groups![indexPath.row])
+        guard let groups = groups,
+            let cell = tableView.dequeueReusableCell(withIdentifier: DKImageGroupCellIdentifier, for: indexPath) as? DKAssetGroupCell else
+        {
+            assertionFailure("Expect groups and cell")
+            return UITableViewCell()
+        }
+		
+        let assetGroup = getImageManager().groupDataManager.fetchGroupWithGroupId(groups[indexPath.row])
         cell.groupNameLabel.text = assetGroup.groupName
 		
 		let tag = indexPath.row + 1

    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        DKPopoverViewController.dismissPopoverViewController()
		
		self.selectedGroup = self.groups![indexPath.row]
		selectedGroupDidChangeBlock?(self.selectedGroup)
    }
	
	// MARK: - DKGroupDataManagerObserver methods
	
	func groupDidUpdate(_ groupId: String) {
		let indexPath = IndexPath(row: self.groups!.index(of: groupId)!, section: 0)
		self.tableView.reloadRows(at: [indexPath], with: .none)
	}
	
	func groupDidRemove(_ groupId: String) {
		let indexPath = IndexPath(row: self.groups!.index(of: groupId)!, section: 0)
		self.groups?.remove(at: indexPath.row)
		self.tableView.deleteRows(at: [indexPath], with: .none)
		
		if self.selectedGroup == groupId {
			self.selectedGroup = self.groups?.first
			selectedGroupDidChangeBlock?(self.selectedGroup)
			self.tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: false, scrollPosition: .none)
		}
	}
    
}

					}
				}
			}
			return groups.first
		}
		return nil
	}
