anchor.diff:      %% the interval covered by chunk is either the biggest key left of startid
       %% or if there are no keys left of startid simply the biggest key in chunk
       {Left, Right} = lists:splitwith(fun({Key, _, _, _, _}) -> Key < StartId end,
  -                                    lists:sort(Chunk)),
  +                                    Chunk),
       Last = case Left of
           [] ->
  -            element(1, lists:last(Right));
  -        _ ->
  -            element(1, lists:last(Left))
  +            element(1, lists:max(Right));
  +        [_|_] ->
  +            element(1, lists:max(Left))
       end,
       ?TRACE_CHUNK("left: ~p~nright: ~p~ncalc_remaining:~n~p~nNext is ~p minus ~p",
                    [Left, Right, Chunk, Interval, intervals:new('[', StartId, Last, ']')]),
  
positive.code:     {Elements, RestInterval} = intervals:get_elements(Interval),
      case intervals:is_empty(RestInterval) of
          true ->
              [E || Key <- Elements, E <- [get_entry(State, Key)], not db_entry:is_empty(E)];
          _ ->
              {_, Data} =
                  get_chunk(State, ?RT:hash_key("0"), % any key will work, here!
                             Interval,
                             fun(DBEntry) ->
                                     (not db_entry:is_empty(DBEntry)) andalso
                                         intervals:in(db_entry:get_key(DBEntry), Interval)
                             end,
                             fun(E) -> E end, all),
              Data
      end.
  
negative.code:         [{interval, LBr, L, R, RBr} | Tail] -> 
              case intervals:in(StartId, intervals:new(LBr, L, R, RBr)) of
                  true ->
                      lists:append([[{interval, '[', StartId, R, RBr}],
                                    Tail, Before,
                                    [{interval, LBr, L, StartId, ')'}]]);
                  _ ->
                      After ++ Before
              end
  