anchor.diff:      NewTargets = cancel_pending_targets(State#state.targets),
       State#state{targets=NewTargets};
   cancel_pending_if_invite_2xx_or_6xx(_Method, Status, State) when is_record(State, state), Status =< 599 ->
  +    %% non-INVITE and not 6xx
       State;
   cancel_pending_if_invite_2xx_or_6xx(_Method, Status, State) when is_record(State, state), Status =< 699 ->
       logger:log(debug, "sipproxy: Cancelling pending targets since one branch resulted in a 6xx response ~p", [Status]),
  
positive.code: 	FivexxResponses /= [] ->
  	    pick_response(5, FivexxResponses);
  	true ->
  	    logger:log(debug, "Appserver: No response to my liking"),
  	    none
      end.	    
  
  %%--------------------------------------------------------------------
  %% Function: aggregate_authreqs(BestResponse, Responses)
  %%           BestResponse = response record()
  %%           Responses    = list() of response record()
  %% Descrip.: Put authentication headers from all responses in
  %%           Responses into the one we have decided to send to our
  %%           parent - BestResponse.
  %% Returns : response record() | none
  %%
  %% Note    : This is described in RFC3261 #16.7 (Response Processing),
  %%           bullet 7. (Aggregate Authorization Header Field Values).
  %%--------------------------------------------------------------------
  %% BestResponse status == 407, Proxy-Authenticate
  aggregate_authreqs(#response{status=407}=BestResponse, Responses) when is_list(Responses) ->
      {Reason, Header} = {BestResponse#response.reason, BestResponse#response.header},
      ProxyAuth = collect_auth_headers(407, 'proxy-authenticate', Responses),
      logger:log(debug, "Aggregating ~p Proxy-Authenticate headers into response '407 ~s'",
  	       [length(ProxyAuth), Reason]),
      NewHeader = keylist:set("Proxy-Authenticate", ProxyAuth, Header),
      BestResponse#response{header=NewHeader};
  %% BestResponse status == 401, WWW-Authenticate
  aggregate_authreqs(#response{status=401}=BestResponse, Responses) when is_list(Responses) ->
      {Reason, Header} = {BestResponse#response.reason, BestResponse#response.header},
      WWWAuth = collect_auth_headers(401, 'www-authenticate', Responses),
      logger:log(debug, "Aggregating ~p WWW-Authenticate headers into response '401 ~s'",
  	       [length(WWWAuth), Reason]),
      NewHeader = keylist:set("WWW-Authenticate", WWWAuth, Header),
      BestResponse#response{header=NewHeader};
  %% BestResponse status is neither 401 nor 407
  aggregate_authreqs(BestResponse, Responses) when is_record(BestResponse, response), is_list(Responses) ->
      BestResponse.
  
  %%--------------------------------------------------------------------
  %% Function: collect_auth_headers(Status, Key, Responses)
  %%           Status    = integer(), SIP status code
  %%           Key       = term(), keylist key of headers to look for
  %%           Responses = list() of response record()
  %% Descrip.: Part of aggregate_authreqs(). Get all headers matched by
  %%           Key from all responses in Responses which have status
  %%           Status.
  
negative.code: %%--------------------------------------------------------------------
  %% Function: fork(State)
  %%           State = state record()
  %% Descrip.: Main loop. Process actions until there are none left.
  %% Returns : ok
  %%--------------------------------------------------------------------
  fork(EndTime, State) when is_integer(EndTime), is_record(State, state), State#state.actions == [] ->
      %% No actions left
      OrigRequest = State#state.request,
      Targets = State#state.targets,
      {Method, ReqURI} = {OrigRequest#request.method, OrigRequest#request.uri},
      NewState =
  	case allterminated(Targets) of
  	    true ->
  		logger:log(debug, "sipproxy: All targets are terminated, terminating"),
  		State;
  	    false ->
  		%% Some targets are not 'terminated'. Even though we cancel them here, they just
  		%% might result in a 2xx response to INVITE (it's a race condition - their response
  		%% might be sent already), so we have to stay alive for a little while to forward
  		%% these 2xx responses to our parent.
  		logger:log(normal, "sipproxy: Reached end of Actions-list for '~s ~s', cancelling pending targets.",
  			   [Method, sipurl:print(ReqURI)]),
  		NewTargets = cancel_pending_targets(Targets),
  
  		State#state.parent ! {sipproxy_no_more_actions, self()},
  
  		logger:log(debug, "sipproxy: waiting ~p seconds for any final responses", [State#state.timeout]),
  		NewEndTime = util:timestamp() + State#state.timeout,
  		NewState1 = case process_wait(false, NewEndTime, State#state{mystate=stayalive, targets=NewTargets}) of
  				{discontinue, NewState1_1} when is_record(NewState1_1, state) -> NewState1_1;
  				NewState1_1 when is_record(NewState1_1, state) -> NewState1_1
  			    end,
  		logger:log(debug, "sipproxy: final responses wait is over, exiting."),
  		NewState1
  	end,
  
      %% Check that this set of actions actually resulted in a final response. Actions can be empty, or
      %% contain only waits or something equally stupid (the stupidity lies in the hand of the end user
      %% with CPL scripts ;) ).
      case NewState#state.final_response_sent of
  	false ->
  	    logger:log(debug, "sipproxy: No final response sent to parent for this set of actions, "
  		       "generating a '500 Server Internal Error'"),
  	    InternalError = {500, "Server Internal Error"},
  	    NewState#state.parent ! {sipproxy_all_terminated, self(), InternalError};
  	_ -> ok
      end,
      ok;
  fork(EndTime, State) when is_integer(EndTime), is_record(State, state) ->
      %% Process first action in list
      OrigRequest = State#state.request,
      [HAction | TAction] = State#state.actions,
  