     }
 
     internal func selectAll() {
-        selectedIndices.removeAll()
-
         let sections = collectionView.numberOfSections
         for section in 0 ..< sections  {
             let items = collectionView.numberOfItems(inSection: section)
             for item in 0 ..< items {
                 let path = IndexPath(item: item, section: section)
                 if collectionView.delegate?.collectionView?(collectionView, shouldSelectItemAt: path) == true {
-                    selectedIndices.append(path)
                     collectionView?.selectItem(at: path, animated: true, scrollPosition: [])
                     collectionView?.delegate?.collectionView?(collectionView, didSelectItemAt: path)
                 }

    @discardableResult internal func setSelected(_ selected: Bool, for indexPath: IndexPath) -> Bool {
        if (collectionView.delegate?.collectionView?(collectionView, shouldSelectItemAt: indexPath) == false && selected)
        || (collectionView.delegate?.collectionView?(collectionView, shouldDeselectItemAt: indexPath) == false && !selected) {
            return selectedIndices.contains(indexPath) //return state of selection, don't do anything
        }

        if selected {
            if selectedIndices.contains(indexPath) {
                return true //already selected, don't do anything
            } else if maxSelectionCount == nil || selectedIndices.count < maxSelectionCount! {
                selectedIndices.append(indexPath)
                collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
                collectionView.delegate?.collectionView?(collectionView, didSelectItemAt: indexPath)
                return true //not already selected and doesn't exceed max, insert
            } else {
                return false //not already selected but exceeds max, don't insert
            }
        } else if let i = selectedIndices.index(of: indexPath) {
            selectedIndices.remove(at: i)
            collectionView.deselectItem(at: indexPath, animated: true)
            collectionView.delegate?.collectionView?(collectionView, didDeselectItemAt: indexPath)
            return false //selected, remove selection

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

