anchor.diff:  	false ->
   	  {reply, {V, S0#state.ck}, S0}
         end;
  -    [{_, V}] ->
  -      {reply, {V, S0#state.ck}, S0};
  -    [_,_|_] ->
  -      io:format(user, "Multiple objects with the same key~n", []),
  -      {reply, hang, S0}
  +    V ->
  +      {reply, {V, S0#state.ck}, S0}
     end.
   
   add_update(X, K, D, W, _T, V1, S0) ->
  -  Ko = lists:keysort(1, K),
  -  Do = lists:keysort(1, D),
  -  case ets:lookup(S0#state.data, {X,Ko,Do}) of
  +  KD = lists:keysort(1, tset:restrict_domain(K, D)),
  +  io:format("Finding ~p ~p~n", [X,KD]),
  +  case tdtree:lookup({X,KD}, S0#state.data) of
       [] ->
         {reply, hang, S0};
  -    [{_, {calc, W}}] ->
  -      Ks = [{Key,Ord} || {{_,Key},Ord} <- Ko],
  -      Ds = [Key || {_,Key} <- Do],
  -      io:format(user, "Adding ~p ~p ~p = ~p~n", [X,Ks,Ds,V1]),
  -      ets:insert(S0#state.data, {{X,Ko,Do}, V1}),
  -      S1 = S0#state{ck = S0#state.ck + 1},
  +    {calc, W} ->
  +      case V1 of
  +	V1 when is_list(V1) ->
  +%%	  io:format(user, "Adding ~p ~p = ~p~n", [X,KD,V1]),
  +	  Tr = tdtree:insert({X,KD,{i,V1,[]}}, S0#state.data);
  +%%	  io:format(user, "Data = ~p~n", [Tr]);
  +	V1 ->
  +%%	  io:format(user, "Adding ~p ~p = ~p~n", [X,KD,V1]),
  +	  Tr = tdtree:insert({X,KD,V1}, S0#state.data)
  +%%	  io:format(user, "Data = ~p~n", [Tr])
  +      end,
  +      S1 = S0#state{data = Tr, ck = S0#state.ck + 1},
         {reply, {V1, S1#state.ck}, S1};
  -    [{_, {calc, _W1}}] ->
  +    {calc, _} = Thr ->
  +      io:format("Wrong thread ~p~n", [Thr]),
         {reply, hang, S0};
  -    [O1,_O2|_Os] ->
  -      io:format(user, "Multiple objects with the same key ~p ~p~n", [W, O1]),
  -      {reply, hang, S0};
  +    Other when is_list(Other) ->
  +      io:format(user, "Other = ~p, W = ~p~nData1 = ~p~n", [Other, W, S0#state.data]),
  +      {reply, {Other, S0#state.ck}, S0};
       Other ->
  -      [{{_X1,_K1,_D1},V1}] = Other,
  -      io:format(user, "Other = ~p, W = ~p~n", [Other, W]),
  -      {reply, hang, S0}
  +      io:format(user, "Other = ~p, W = ~p~nData1 = ~p~n", [Other, W, S0#state.data]),
  +      {reply, {Other, S0#state.ck}, S0}
     end.
   
   %%------------------------------------------------------------------------------
  
positive.code:   {ok, #state{ limit = Limit }}.
  
  terminate(_, S) ->
    true = ets:delete(S#state.data),
    ok.
  
  %%------------------------------------------------------------------------------
  
negative.code: -record(state, { 
  	  ck    = 0,
  	  age   = 2,
  	  data  = tdtree:new(),
  	  limit = undefined
  	 }).
  
  