anchor.diff:    write(File, BlockSize, replace(Parent, ToReplace, Left, Right));
     
   split_child(Parent = #node{keys=Keys,children=Children}, ToReplace, Child = #node{m=M,keys=ChildKeys,children=ChildChildren}, #dmerkle{file=File,block=BlockSize}) ->
  -  % error_logger:info_msg("splitting node ~n"),
  -  KeyHash = lists:nth(M div 2, Keys),
  +  % error_logger:info_msg("splitting node ~p~n", [Parent]),
  +  % KeyHash = lists:nth(M div 2, Keys),
     {LeftKeys, RightKeys} = lists:split((M div 2)-1, ChildKeys),
     {LeftChildren, RightChildren} = lists:split(M div 2, ChildChildren),
  +    % error_logger:info_msg("rightkeys ~p rightchildren ~p leftkeys ~p leftchildren ~p~n", [length(RightKeys), length(RightChildren), length(LeftKeys), length(LeftChildren)]),
     Left = write(File, BlockSize, #node{m=length(LeftKeys),keys=LeftKeys,children=LeftChildren}),
     Right = write(File, BlockSize, Child#node{m=length(RightKeys),keys=RightKeys,children=RightChildren}),
     write(File, BlockSize, replace(Parent, ToReplace, Left, Right)).
  
positive.code: 
  update(KeyHash, Key, Value, Node = #node{children=Children,keys=Keys}, Tree = #dmerkle{d=D,file=File,block=BlockSize}) ->
    {FoundKey, {ChildHash,ChildPointer}} = find_child(KeyHash, Keys, Children),
    Child = read(File,ChildPointer,BlockSize),
    case m(Child) of
      M when M >= D -> update(KeyHash, Key, Value, split_child(Node, FoundKey, Child, Tree), Tree);
  
negative.code:   M = m(Root),
    if
      M >= D-1 -> %allocate new root, move old root and split
        FinalRoot = split_child(#node{}, empty, Root, Tree),
        update_root_pointer(File, FinalRoot),
        Tree#dmerkle{root=update(hash(Key), Key, Value, FinalRoot, Tree)};
      true -> Tree#dmerkle{root=update(hash(Key), Key, Value, Root, Tree)}
  