anchor.diff:  						request1(RequestType, Request, SId, RequestNum, Subscriber,
   								Balance, OHost, ORealm, State);
   					{error, _} ->
  -						send_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_AUTHORIZATION_REJECTED',
  -								OHost, ORealm, ?CC_APPLICATION_ID, RequestType, RequestNum, State)
  +						{Reply, NewState} = generate_diameter_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_AUTHORIZATION_REJECTED',
  +								OHost, ORealm, ?CC_APPLICATION_ID, RequestType, RequestNum, State),
  +						{reply, Reply, NewState}
   				end;
   			{error, _} ->
  -				send_error(Request, SId, undefined, undefined, ?'DIAMETER_BASE_RESULT-CODE_AUTHORIZATION_REJECTED',
  -					OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  -						RequestNum, State)
  +				{Reply, NewState} = generate_diameter_error(Request, SId, undefined, undefined, ?'DIAMETER_BASE_RESULT-CODE_AUTHORIZATION_REJECTED',
  +					OHost, ORealm, ?CC_APPLICATION_ID, RequestType, RequestNum, State),
  +				{reply, Reply, NewState}
   		end
   	catch
   		_:_ ->
  -			send_error(Request, SId, undefined, undefined,
  +			{Reply1, NewState1} = generate_diameter_error(Request, SId, undefined, undefined,
   					?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY', OHost, ORealm,
  -					?CC_APPLICATION_ID, RequestType, RequestNum, State)
  +					?CC_APPLICATION_ID, RequestType, RequestNum, State),
  +			{reply, Reply1, NewState1}
   	end.
   
   %% @hidden
   request1(?'DIAMETER_CC_APP_CC-REQUEST-TYPE_INITIAL_REQUEST' = RequestType,
   		Request, SId, RequestNum, Subscriber, Balance, OHost, ORealm, State) ->
  -	send_answer(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_SUCCESS',
  +	{Reply, NewState} = generate_diameter_answer(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_SUCCESS',
   			OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  -			RequestNum, State);
  +			RequestNum, State),
  +	{reply, Reply, NewState};
   request1(?'DIAMETER_CC_APP_CC-REQUEST-TYPE_UPDATE_REQUEST' = RequestType,
   		Request, SId, RequestNum, Subscriber, Balance, OHost, ORealm, State) ->
   	try
  
positive.code: 		end,
  		case decrement_balance(Subscriber, Usage) of
  			{ok, OverUsed, false} when OverUsed =< 0 ->
  				send_answer(Request, SId, Subscriber, 0, ?'DIAMETER_CC_APP_RESULT-CODE_CREDIT_LIMIT_REACHED',
  						OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  						RequestNum, State);
  			{ok, SufficientBalance, _Flags} ->
  				send_answer(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_SUCCESS',
  						OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  						RequestNum, State);
  			{error, not_found} ->
  				error_logger:warning_report(["diameter accounting subscriber not found",
  						{module, ?MODULE}, {subscriber, Subscriber},
  						{origin_host, OHost}]),
  				send_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  						OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  						RequestNum, State)
  		end
  	catch
  		_:_ ->
  			send_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  					OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  					RequestNum, State)
  	end;
  request1(?'DIAMETER_CC_APP_CC-REQUEST-TYPE_TERMINATION_REQUEST' = RequestType,
  		Request, SId, RequestNum, Subscriber, Balance, OHost, ORealm, State) ->
  
negative.code: 	end,
  	case mnesia:transaction(F) of
  		{atomic, ok} ->
  			{Reply, NewState} = generate_diameter_answer(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_SUCCESS',
  					OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  					RequestNum, State),
  			{reply, Reply, NewState};
  		{aborted, Reason} ->
  			error_logger:error_report(["Failed to disconnect subscriber",
  					{subscriber, Subscriber}, {origin_host, OHost},
  					{origin_realm, ORealm},{session, SId}, {state, State},
  					{reason, Reason}]),
  			{Reply, NewState} = generate_diameter_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  					OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  					RequestNum, State),
  			{reply, Reply, NewState}
  	end.
  
  -spec generate_diameter_answer(Request, SessionId, Subscriber, Balance, ResultCode, OriginHost, OriginRealm,
  		AuthAppId, RequestType, RequestNum, State) -> Result
  			when
  				Request :: #diameter_cc_app_CCR{},
  