anchor.diff:           Fd, {ParentMbr, #node{type=inner}, PosList}),
       {ParentMbr, ParentPos}.
   
  -
  +% XXX vmx: insert_subtree and potentially other functions should be moved
  +%     from the vtree_bulk to the vtree module
   % @doc inserts a subtree into an vtree at a specific level. Returns the
   % MBR and position in the file of the new root node.
   -spec insert_subtree(Fd::file:io_device(), RootPos::integer(),
  -        Subtree::{mbr(), integer()}, Level::integer()) ->
  +        Subtree::[{mbr(), integer()}], Level::integer()) ->
           {ok, mbr(), integer()}.
   insert_subtree(Fd, RootPos, Subtree, Level) ->
  -    insert_subtree(Fd, RootPos, Subtree, Level, 0).
  +    %insert_subtree(Fd, RootPos, Subtree, Level, 0),
  +    case insert_subtree(Fd, RootPos, Subtree, Level, 0) of
  +    {splitted, NodeMbr, {Node1Mbr, NodePos1}, {Node2Mbr, NodePos2}} ->
  +        Parent = {NodeMbr, #node{type=inner}, [NodePos1, NodePos2]},
  +        {ok, Pos} = couch_file:append_term(Fd, Parent),
  +        {ok, NodeMbr, Pos};
  +    {ok, NewMbr, NewPos} ->
  +        {ok, NewMbr, NewPos}
  +    end.
   
   -spec insert_subtree(Fd::file:io_device(), RootPos::integer(),
  -        Subtree::{mbr(), integer()}, Level::integer(), Depth::integer()) ->
  -        {ok, integer()}.
  +        Subtree::[{mbr(), integer()}], Level::integer(), Depth::integer()) ->
  +        {ok, mbr(), integer()} |
  +        {splitted, mbr(), {mbr(), integer()}, {mbr(), integer()}}.
   insert_subtree(Fd, RootPos, Subtree, Level, Depth) when Depth==Level ->
  -    {SubtreeMbr, SubtreePos} = Subtree,
  +?debugMsg("still works"),
  +?debugVal(RootPos),
  +?debugVal(Subtree),
  +    %{SubtreeMbr, SubtreePos} = Subtree,
  +    {SubtreeMbrs, SubtreePosList} = lists:unzip(Subtree),
       {ok, Parent} = couch_file:pread_term(Fd, RootPos),
       {ParentMbr, ParentMeta, EntriesPos} = Parent,
  -    MergedMbr = vtree:merge_mbr(SubtreeMbr, ParentMbr),
  -
  -    ChildrenPos = [SubtreePos|EntriesPos],
  +    %MergedMbr = vtree:merge_mbr(SubtreeMbr, ParentMbr),
  +    MergedMbr = vtree:calc_mbr([ParentMbr|SubtreeMbrs]),
  +?debugVal(MergedMbr),
  +
  +    %ChildrenPos = [SubtreePos|EntriesPos],
  +    ChildrenPos = SubtreePosList ++ EntriesPos,
  +    %ChildrenPos = [RootPos|SubtreePosList],
  +?debugVal(ChildrenPos),
       if
       length(ChildrenPos) =< ?MAX_FILLED ->
           NewNode = {MergedMbr, ParentMeta, ChildrenPos},
  
positive.code: 
  % XXX vmx: needs tests
  % @doc Find the node that needs least expension for the given MBR and returns
  % the MBR and positio of the node together with the original children MBRs and
  % positions in the file.
  -spec least_expansion(Fd::file:io_device(), NewMbr::mbr,
          PosList::[integer()]) -> {{mbr, integer()}, [{mbr, integer()}]}.
  
negative.code:     LeafDepths5 = vtreestats:leaf_depths(Fd5, ResultPos5),
      ?assertEqual([4], LeafDepths5).
  
  insert_subtree_test() ->
      {ok, {Fd, {RootPos, TreeHeight}}} = vtree_test:build_random_tree(
              "/tmp/randtree.bin", 20),
  