      `true` for selected, `false` for deselected.
      */
     @discardableResult internal func toggleSelected(indexPath: IndexPath) -> Bool {
-        if let i = selectedIndices.index(of:indexPath) { //is selected, attempt remove selection
+        if collectionView.indexPathsForSelectedItems?.contains(indexPath) == true { //is selected, attempt remove selection
             if collectionView.delegate?.collectionView?(collectionView, shouldDeselectItemAt: indexPath) == true {
-                selectedIndices.remove(at: i)
                 collectionView.deselectItem(at: indexPath, animated: true)
                 collectionView.delegate?.collectionView?(collectionView, didDeselectItemAt: indexPath)
                 return false
             } else { return true } //deselection disallowed, keep selected
         } else { //is unselected, attempt selection
             if collectionView.delegate?.collectionView?(collectionView, shouldSelectItemAt: indexPath) == true &&
-            (maxSelectionCount == nil || selectedIndices.count < maxSelectionCount!) {
-                selectedIndices.append(indexPath)
+            (maxSelectionCount == nil || collectionView.indexPathsForSelectedItems?.count ?? 0 < maxSelectionCount!) {
                 collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
                 collectionView.delegate?.collectionView?(collectionView, didSelectItemAt: indexPath)
                 return true

    }

    internal func clearSelected() {
        for i in stride(from: selectedIndices.count-1, through: 0, by: -1) {
            let path = selectedIndices[i]
            selectedIndices.remove(at: i)
            collectionView?.deselectItem(at: path, animated: true)
            collectionView?.delegate?.collectionView?(collectionView, didDeselectItemAt: path)
        }
    }

    internal func getSelectedCount() -> Int {
        return selectedIndices.count
    }

    internal func isIndexSelected(_ indexPath: IndexPath) -> Bool {
        return selectedIndices.contains(indexPath)
    }
}

                    self.setSelected(false, for: indexPath)
                }
            })
        }
    }

