anchor.diff:      {level_done, Level} = seedtree_write(Fd, [Tree], InsertHeight, []),
       ?debugMsg("almost done."),
       ?debugVal(Level),
  +    ?debugVal(length(Level)),
       Root = if
       length(Level) == 1 ->
  -        hd(Level);
  +    %    hd(Level);
  +        Level;
  +    % NOTE vmx: not sure why this can't be done in the {level_done, _} case
  +    length(Level) > ?MAX_FILLED ->
  +        ?debugMsg("overflow"),
  +        {Level2, _} = omt_load(Level, ?MAX_FILLED),
  +        
  +        Parents = lists:foldl(fun(Level3, LevelAcc) ->
  +            ParentMbr = vtree:calc_nodes_mbr(Level3),
  +            ChildrenPos = write_nodes(Fd, Level3),
  +            % XXX vmx: Not sure if type=inner is always right
  +            Parent = {ParentMbr, #node{type=inner}, ChildrenPos},
  +            [Parent|LevelAcc]
  +        end, [], Level2),
  +        ?debugVal(Parents),
  +        MbrAndPosList = [{Mbr, Pos} || {Mbr, _, Pos} <- Parents];
  +        %{ok, [Parents|Acc]}
  +        %{ok, Parents}
  +        %Parents;
  +%         Level;
       true ->
  +?debugMsg("Fooooooooooooooo"),
           ParentMbr = vtree:calc_nodes_mbr(Level),
           ChildrenPos = write_nodes(Fd, Level),
  -        {ParentMbr, #node{type=inner}, ChildrenPos}
  +        %{ParentMbr, #node{type=inner}, ChildrenPos}
  +        [{ParentMbr, #node{type=inner}, ChildrenPos}]
       end,
       ?debugVal(Root),
  +    {ok, Root}.
   
   %    {ok, Pos} = couch_file:append_term(Fd, Parent),
  -    {ok, Pos} = couch_file:append_term(Fd, Root),
  -    %{ok, Acc} = seedtree_write(Fd, [Tree], InsertHeight, []),
  -    %{level_done, [{_,_,[Pos]}]} = seedtree_write(Fd, [Tree], InsertHeight, []),
  -
  -    % Insert outliers one by one
  -    {Pos2, TreeHeight} = lists:foldl(fun(
  -            {Mbr, Meta, {DocId, Value}}=Foo, {CurPos, _}) ->
  -        {ok, _NewMbr, CurPos2, TreeHeight} = vtree:insert(
  -                Fd, CurPos, DocId, {Mbr, Meta, Value}),
  -        {CurPos2, TreeHeight}
  -    end, {Pos, 0}, Seedtree#seedtree_root.outliers),
  -    {ok, Pos2}.
  +    %{ok, Pos} = couch_file:append_term(Fd, Root),
  +%    MbrAndPosList = lists:map(fun({NodeMbr, _, _}=Node) ->
  +%?debugVal(Node),
  +%        {ok, NodePos} = couch_file:append_term(Fd, Node),
  +%?debugVal(NodePos),
  +%        {NodeMbr, [NodePos]}
  +%    end, Root),
  +%?debugVal(MbrAndPosList),
  +%?debugVal(element(2, hd(MbrAndPosList))),
  +%?debugVal(tl(MbrAndPosList)),
  +
  +
  +%    MbrAndPosList = [{Mbr, Pos} || {Mbr, _, Pos} <- Root],
  +%    {ok, MbrAndPosList}.
  +
  +
  +%    ParentMbr2 = vtree:calc_nodes_mbr(Root),
  +%    ChildrenPos2 = write_nodes(Fd, Root),
  +%?debugVal(ChildrenPos2),
  +%    % XXX vmx: Not sure if type=inner is always right
  +%    MbrAndPosList = [{ParentMbr2, ChildrenPos2}],
  +%    {ok, MbrAndPosList}.
  +
  + 
  +%    % XXX vmx: OUTLINER INSERTION IS DISABLED ATM
  +%    % Insert outliers one by one
  +%    {MbrAndPos, TreeHeight} = lists:foldl(fun(
  +%            {Mbr, Meta, {DocId, Value}}=Foo, {{_, CurPos}, _}) ->
  +%        {ok, NewMbr, CurPos2, TreeHeight} = vtree:insert(
  +%                Fd, CurPos, DocId, {Mbr, Meta, Value}),
  +%        {{NewMbr, CurPos2}, TreeHeight}
  +%    %end, {Pos, 0}, Seedtree#seedtree_root.outliers),
  +%    %{ok, Pos2}.
  +%    end, {hd(MbrAndPosList), -1}, Seedtree#seedtree_root.outliers),
  +%    ?debugVal(MbrAndPos),
  +%    {ok, [MbrAndPos|tl(MbrAndPosList)]}.
  +
   seedtree_write(_Fd, [], InsertHeight, Acc) ->
       ?debugMsg("No more siblings!!!!!!!!!!!!!!!!!!"),
       {no_more_siblings, Acc};
  
positive.code:     {ok, Lookup5} = vtree:lookup(Fd5, ResultPos5, {0,0,1001,1001}),
      ?assertEqual(296, length(Lookup5)).
  
  seedtree_write_case3_test() ->
      % Test "Case 3: input R-tree is shorter than the level of the child level of the target node" (chapter 6.3)
      % Test 3.1: input tree is too small (1 level)
      TargetTreeNodeNum = 25,
  
negative.code: % leaf node
  omt_write_tree(Fd, [H|_T]=Leafs, Depth, _Acc) when is_tuple(H) ->
      %{leaf_nodes, Leafs};
      %?debugVal(length(Leafs)),
      %?debugVal(Leafs),
      % Don't write leafs nodes to disk now, they will be written later on.
      % Instead return a list of of tuples with the node's MBR and the node
      % itself
  