             return tableView.frame.size.height - tableView.contentInset.top
         }
     }
-
+    
     // MARK: - Functions
     
     open func indexPaths(toInsert cells: [UITableViewCell]) -> [IndexPath] {
         var indexPaths = [IndexPath]()
         for section in 0 ..< super.numberOfSections(in: tableView) {
             var numberOfExcludedRows = 0
-            for row in 0 ..< super.tableView(tableView, numberOfRowsInSection: section) {
+            for row in 0 ..< super.tableView(tableView, numberOfRowsInSection: superSection(forSection: section)) {
                 let superIndexPath = IndexPath(row: row, section: section)
                 let superCell = super.tableView(tableView, cellForRowAt: superIndexPath)
                 if cells.contains(superCell) && tableView.indexPath(for: superCell) == nil {

        return numberOfExcludedRows
    }
    
    private func numberOfExcludedRows(inSection section: Int) -> Int {
        let numberOfRowsInSection = super.tableView(tableView, numberOfRowsInSection: section)
        let indexPath = IndexPath(row: numberOfRowsInSection - 1, section: section)
        return numberOfExcludedRowsInSection(before: indexPath)
    }
    
    private func shouldHideSection(_ section: Int) -> Bool {
        return numberOfExcludedRows(inSection: section) == super.tableView(tableView, numberOfRowsInSection: section)
    }
    
    private func superSection(forSection section: Int) -> Int {
        return section + numberOfExcludedSections(beforeSection: section)
    }
    
    fileprivate func superIndexPath(for indexPath: IndexPath) -> IndexPath {
        return IndexPath(row: indexPath.row + numberOfExcludedRowsInSection(before: indexPath),
                         section: superSection(forSection: indexPath.section))
    }
    
    fileprivate func refreshCellHeights() {
        CATransaction.begin()
        shouldCallHeightForRow = false
        CATransaction.setCompletionBlock {

    
    open override func numberOfSections(in tableView: UITableView) -> Int {
        var numberOfSections = 0
        for superSection in 0 ..< super.numberOfSections(in: tableView) {
            if shouldInclude(superSection: superSection) {
                numberOfSections += 1
            }
        }
        return numberOfSections
    }
    
    open override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return super.tableView(tableView, heightForHeaderInSection: superSection(forSection: section))
    }
    
    open override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return super.tableView(tableView, heightForFooterInSection: superSection(forSection: section))
    }
    
    open override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return super.tableView(tableView, titleForHeaderInSection: superSection(forSection: section))
    }
    
    open override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
        return super.tableView(tableView, titleForFooterInSection: superSection(forSection: section))
    }
    
    open override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return super.tableView(tableView, viewForHeaderInSection: superSection(forSection: section))
    }
    
    open override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return super.tableView(tableView, viewForFooterInSection: superSection(forSection: section))
    }
    
    open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let superSection = self.superSection(forSection: section)
        let numberOfRowsInSuperSection = super.tableView(tableView, numberOfRowsInSection: superSection)
        let numberOfExcludedRowsInThisSection: Int = numberOfRowsInSuperSection == 0
            ? 0
            : numberOfExcludedRows(inSuperSection: superSection)
        return numberOfRowsInSuperSection - numberOfExcludedRowsInThisSection
    }
    
    open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
