     
     func addPairs(_ newPairs : [(T,PageId)], replacingIndex index : Int, totalCount newTotal: UInt64) throws {
         self.totalCount = newTotal
+        
+        let replacing = self.pairs[index]
+        self.serializedSize -= replacing.0.serializedSize + replacing.1.serializedSize
+        for (k,v) in newPairs {
+            self.serializedSize += k.serializedSize
+            self.serializedSize += v.serializedSize
+        }
+        
         self.pairs.replaceSubrange(index...index, with: newPairs)
+        self.max = self.pairs.last!.0
     }
     
     func serialize(to buffer : UnsafeMutablePointer<Void>, pageSize : Int) throws {

        if leaf.spaceForPair(pair, pageSize: m.pageSize) {
//            print("- there is space in the \(leafStatus) leaf for the add")
            try leaf.addPair(pair)
            let max = leaf.interval!.max
            
            let leafNode : TreeNode<T,U> = .leafNode(leaf)
            if case .dirty(let pid) = leafStatus {

        
        var next = iter.peek()
        while next != nil {
            let serializedSize = next!.0.serializedSize + next!.1.serializedSize
            if remainingBytes < serializedSize {
                break
            }
