         toggleCollapse(viewModel)
         if wasCollapsed {
             tableView.insertRows(at: indexPaths, with: (hasAnimation ? .automatic : .none))
+            visibleChildren[indexPath.section]?.insert(contentsOf: neededVisibleChildren,
+                                                       at: indexPath.row)
         } else {
             delegate?.collapsableTableViewDataSource(self, willHideCellsAt: indexPaths, at: tableView)
             tableView.deleteRows(at: indexPaths, with: (hasAnimation ? .top : .none))
+            let removeSubrange = indexPath.row...indexPath.row+neededChildrenCount-1
+            visibleChildren[indexPath.section]?.removeSubrange(removeSubrange)
         }
         tableView.reloadRows(at: [indexPath], with: .none)
-        visibleChildren.removeValue(forKey: indexPath.section)
         tableView.endUpdates()
         return true
     }

        }
        
        let neededChildrenCount: Int
        if isCollapsed(viewModel) {
            neededChildrenCount = viewModel.children.count + viewModel.children.reduce(0, { $0 + $1.visibleChildrenCount(isCollapsed) })
        } else {
            neededChildrenCount = viewModel.visibleChildrenCount(isCollapsed)
        }
        let range = indexPath.row+1...indexPath.row+neededChildrenCount
        let indexPaths = range.map { return IndexPath(row: $0, section: indexPath.section) }

    private var visibleChildren: [Int: [Item]] = [:]

    private func visibleChildren(for section: Int) -> [Item] {
        if visibleChildren[section] == nil {
            visibleChildren[section] = displayedRows[section].visibleChildren(isCollapsed)
        }
        return visibleChildren[section] ?? []
    }
}
