anchor.diff:              let LEAF_PAGE_OVERHEAD = 2 + 4 + 2 + 4
               let OFFSET_COUNT_PAIRS = 6
   
  -            // TODO this wants to be an F# list
  -            let leaves = new System.Collections.Generic.List<int32 * byte[]>()
  -
  -            let flushLeaf countPairs lastKey thisPageNumber boundaryPageNumber = 
  -                pb.PutInt16At (OFFSET_COUNT_PAIRS, countPairs)
  -                let isRootPage = not (csr.IsValid()) && (0 = leaves.Count)
  -                let range = 
  -                    if (not isRootPage) && (thisPageNumber = boundaryPageNumber) then
  +            let flushLeaf st isRootPage = 
  +                pb.PutInt16At (OFFSET_COUNT_PAIRS, st.keys.Length)
  +                let thisPageNumber = st.nextPage
  +                let (nextN,nextB) = 
  +                    if (not isRootPage) && (thisPageNumber = st.boundaryPage) then
                           pb.SetPageFlag FLAG_BOUNDARY_NODE
                           let newRange = pageManager.GetRange(token)
                           // assert pb.Position <= (pageSize - 4)
                           pb.SetLastInt32(fst newRange)
                           newRange
                       else
  -                        (thisPageNumber + 1, boundaryPageNumber)
  +                        (thisPageNumber + 1, st.boundaryPage)
                   pb.Flush(fs)
                   pb.Reset()
  -                leaves.Add(thisPageNumber, lastKey)
  -                let nextPage = fst range
  -                if nextPage <> (thisPageNumber+1) then utils.SeekPage(fs, pageSize, nextPage)
  -                range
  -
  -            let rec putKeys countPairs lastKey nextPageNumber boundaryPageNumber =
  -                let k = csr.Key()
  -                let v = csr.Value()
  +                if nextN <> (thisPageNumber+1) then utils.SeekPage(fs, pageSize, nextN)
  +                {keys=[]; nextPage=nextN; boundaryPage=nextB; leaves=(thisPageNumber,List.head st.keys)::st.leaves}
  +
  +            let folder st (pair:(byte[]*Stream)) = 
  +                let (k,v) = pair
                   // assert k <> null
                   // but v might be null (a tombstone)
   
  
positive.code:         // maybe more than one level of them.
          // keep writing until we have written a level which has only one node,
          // which is the root node.
          if leaves.Count > 0 then
              let firstLeaf = fst leaves.[0]
              let lastLeaf = fst leaves.[leaves.Count-1]
  
              let writeParentNodes children startingPageNumber startingBoundaryPageNumber =
                  // 2 for the page type and flags
  
negative.code:                             else
                                  let (n,b) = putOverflow (new MemoryStream(k)) nextPageNumber boundaryPageNumber
                                  putOverflow v n b
                      {st with nextPage=newN;boundaryPage=newB;keys=k::st.keys}
                          
                  // this is the body of the folder function
                  maybeFlushLeaf st |> initLeaf |> addPairToLeaf
  
              // this is the body of writeLeaves
              let source = seq { csr.First(); while csr.IsValid() do yield (csr.Key(), csr.Value()); csr.Next(); done }
              let initialState = {keys=[];leaves=[];nextPage=leavesFirstPage;boundaryPage=leavesBoundaryPage}
              let middleState = Seq.fold folder initialState source
              let finalState = 
                  if middleState.keys.Length > 0 then
                      let isRootNode = middleState.leaves.Length=0
                      flushLeaf middleState isRootNode
                  else
                      middleState
              let {nextPage=n;boundaryPage=b;leaves=leaves} = finalState
              (n,b,leaves)
  
          // this is the body of Create
          let (startingPage,startingBoundary) = pageManager.GetRange(token)
          utils.SeekPage(fs, pageSize, startingPage)
  
          let (pageAfterLeaves, boundaryAfterLeaves, leaves) = writeLeaves startingPage startingBoundary
  
          // all the leaves are written.
  