anchor.diff:                      maybeFlush st |> initParent |> addKeyToParent
   
                   // this is the body of writeParentNodes
  -                // TODO this would be much happier if children were already an F# list
  -                let fsChildren = (List.ofSeq children) |> List.rev
  -                let h = List.head fsChildren
  -                let t = List.tail fsChildren
  -                let initialState = {sofar=0;items=[];nextPage=startingPageNumber;boundaryPage=startingBoundaryPageNumber;overflows=Map.empty}
  -                let middleState = List.foldBack folder t initialState 
  -                let finalState = flushParentPage middleState h (nextGeneration.Count=0)
  -                let {nextPage=n;boundaryPage=b} = finalState
  -                (n,b,nextGeneration)
  -
  -            let rec writeOneLayerOfParentPages next boundary (children:System.Collections.Generic.List<int32 * byte[]>) :int32 =
  -                if children.Count > 1 then
  +                // children is in reverse order.  so List.head children is actually the very last child.
  +                let lastChild = List.head children
  +                let initialState = {nextGeneration=[];sofar=0;items=[];nextPage=startingPageNumber;boundaryPage=startingBoundaryPageNumber;overflows=Map.empty}
  +                let middleState = List.foldBack folder (List.tail children) initialState 
  +                let isRootNode = (middleState.nextGeneration.Length=0)
  +                let finalState = flushParentPage middleState lastChild isRootNode
  +                let {nextPage=n;boundaryPage=b;nextGeneration=ng} = finalState
  +                (n,b,ng)
  +
  +            let rec writeOneLayerOfParentPages next boundary (children:(int32*byte[]) list) :int32 =
  +                if children.Length > 1 then
                       let (newNext,newBoundary,newChildren) = writeParentNodes children next boundary 
                       writeOneLayerOfParentPages newNext newBoundary newChildren
                   else
                       fst children.[0]
   
  -            let rootPage = writeOneLayerOfParentPages pageAfterLeaves boundaryAfterLeaves leaves
  +            let rootPage = writeOneLayerOfParentPages pageAfterLeaves boundaryAfterLeaves (List.rev (List.ofSeq leaves))
   
               pageManager.End(token, rootPage)
               rootPage
  
positive.code:                                 (thisPageNumber+1,boundaryPageNumber)
                      pb.Flush(fs)
                      if nextN <> (thisPageNumber+1) then utils.SeekPage(fs, pageSize, nextN)
                      nextGeneration.Add(thisPageNumber, k)
                      {sofar=0; items=[]; nextPage=nextN; boundaryPage=nextB; overflows=Map.empty}
  
                  let folder pair st =
                      let (pagenum,k:byte[]) = pair
  
negative.code:                     let neededEitherWay = 1 + Varint.SpaceNeededFor (int64 k.Length) + Varint.SpaceNeededFor (int64 pagenum)
                      let neededForInline = neededEitherWay + k.Length
                      let neededForOverflow = neededEitherWay + sizeof<int32>
                      let couldBeRoot = (st.nextGeneration.Length = 0)
  
                      let maybeFlush st = 
                          let available = calcAvailable (st.sofar) couldBeRoot
  