anchor.diff:  %% External functions
   %%====================================================================
   
  -add(Branch, Request, Pid, State, Timeout, DstList, TargetList) when is_record(Request, request),
  +%%--------------------------------------------------------------------
  +%% Function: add(Branch, Request, Pid, State, Timeout, DstList,
  +%%               TargetList)
  +%%           Branch     = string()
  +%%           Request    = request record()
  +%%           Pid        = pid()
  +%%           State      = atom()
  +%%           Timeout    = integer()
  +%%           DstList    = list() of sipdst record()
  +%%           TargetList = targetlist record()
  +%% Descrip.: Add a new entry to TargetList, after verifying that a
  +%%           target with this branch is not already in the list.
  +%% Returns : NewTargetList = targetlist record()
  +%%--------------------------------------------------------------------
  +add(Branch, Request, Pid, State, Timeout, DstList, TargetList) when is_list(Branch), is_record(Request, request),
  +								    is_pid(Pid), is_atom(State), is_integer(Timeout),
  +								    is_list(DstList),
   								    is_record(TargetList, targetlist) ->
       case get_using_branch(Branch, TargetList) of
   	none ->
   	    NewTarget = #target{ref=make_ref(), branch=Branch, request=Request, pid=Pid, state=State,
  -		   		endresult=none, dstlist=DstList, timeout=Timeout},
  +		   		dstlist=DstList, timeout=Timeout},
   	    #targetlist{list=lists:append(TargetList#targetlist.list, [NewTarget])};
  -	_ ->
  +	T when is_record(T, target) ->
   	    logger:log(error, "targetlist: Asked to add target with duplicate branch ~p to list :~n~p",
   	    	       [branch, debugfriendly(TargetList)]),
   	    TargetList
       end.
   
  +%%--------------------------------------------------------------------
  +%% Function: empty()
  +%% Descrip.: Return empty targetlist record. For initialization.
  +%% Returns : TargetList = targetlist record()
  +%%--------------------------------------------------------------------
   empty() ->
       #targetlist{list=[]}.
   
  -list_length(TargetList) when is_record(TargetList, targetlist) ->
  +%%--------------------------------------------------------------------
  +%% Function: get_length(TargetList)
  +%%           TargetList = targetlist record()
  +%% Descrip.: Return length of list encapsulated in the TargetList
  +%%           record.
  +%% Returns : Length = integer()
  +%%--------------------------------------------------------------------
  +get_length(TargetList) when is_record(TargetList, targetlist) ->
       length(TargetList#targetlist.list).
   
  +%%--------------------------------------------------------------------
  +%% Function: update_target(Target, TargetList)
  +%%           Target     = target record()
  +%%           TargetList = targetlist record()
  +%% Descrip.: Locate the old instance of the target Target in
  +%%           the TargetList and exchange it with Target.
  +%% Returns : NewTargetList = list() of target record() | throw(...)
  +%%--------------------------------------------------------------------
   update_target(Target, TargetList) when is_record(Target, target), is_record(TargetList, targetlist) ->
       Ref = Target#target.ref,
  -    #targetlist{list=update_target(Ref, Target, TargetList#targetlist.list, TargetList)}.
  -
  -update_target(Ref, _, [], TargetList) ->
  +    NewList = update_target2(Ref, Target, TargetList#targetlist.list, []),
  +    #targetlist{list=NewList}.
  +
  +update_target2(Ref, _NewT, [], Res) ->
       logger:log(error, "Targetlist: Asked to update a target, but I can't find it"),
       logger:log(debug, "Targetlist: Asked to update a target with ref=~p, but I can't find it in list :~n~p",
  -		[Ref, debugfriendly(TargetList)]),
  -    [];
  -update_target(Ref, NewT, [H | T], _TargetList) when is_record(H, target), H#target.ref == Ref ->
  -    [NewT | T];
  -update_target(Ref, NewT, [H | T], TargetList) when is_record(H, target) ->
  -    lists:append([H], update_target(Ref, NewT, T, TargetList)).
  -
  +	       [Ref, debugfriendly2( lists:reverse(Res), [])]),
  +    throw({error, update_of_non_existin_target});
  +update_target2(Ref, NewT, [#target{ref=Ref} | T], Res) ->
  +    %% Match
  +    Head = lists:reverse([NewT | Res]),
  +    Head ++ T;
  +update_target2(Ref, NewT, [H | T], Res) when is_record(H, target) ->
  +    %% No match
  +    update_target2(Ref, NewT, T, [H | Res]).
  +
  +%%--------------------------------------------------------------------
  +%% Function: debugfriendly(TargetList)
  +%%           TargetList = targetlist record()
  +%% Descrip.: Format the entrys in TargetList in a way that is suitable
  +%%           for logging using ~p.
  +%% Returns : Data = term()
  +%%--------------------------------------------------------------------
   debugfriendly(TargetList) when is_record(TargetList, targetlist) ->
       debugfriendly2(TargetList#targetlist.list, []).
   
  
positive.code: -export([
  	 add/7,
  	 empty/0,
  	 list_length/1,
  	 debugfriendly/1,
  	 get_using_branch/2,
  	 get_targets_in_state/2,
  	 get_responses/1,
  
negative.code: 	 set_endresult/2,
  	 set_dstlist/2,
  	 set_cancelled/2,
  	 update_target/2,
  
  	 test/0
  	]).
  
  %%--------------------------------------------------------------------
  %% Include files
  %%--------------------------------------------------------------------
  -include("siprecords.hrl").
  -include("sipproxy.hrl").
  
  %%--------------------------------------------------------------------
  %% Records
  