anchor.diff:  		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',
  +				{Reply, NewState} = generate_diameter_answer(Request, SId, Subscriber, 0, ?'DIAMETER_CC_APP_RESULT-CODE_CREDIT_LIMIT_REACHED',
  +						OHost, ORealm, ?CC_APPLICATION_ID, RequestType, RequestNum, State),
  +				{reply, Reply, NewState};
  +			{ok, SufficientBalance, _Flags} ->
  +				{Reply, NewState} = generate_diameter_answer(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_SUCCESS',
   						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);
  +						RequestNum, State),
  +				{reply, Reply, NewState};
   			{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',
  +				{Reply, NewState} = generate_diameter_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
   						OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  -						RequestNum, State)
  +						RequestNum, State),
  +				{reply, Reply, NewState}
   		end
   	catch
   		_:_ ->
  -			send_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
  +			{Reply1, NewState1} = generate_diameter_error(Request, SId, Subscriber, Balance, ?'DIAMETER_BASE_RESULT-CODE_UNABLE_TO_COMPLY',
   					OHost, ORealm, ?CC_APPLICATION_ID, RequestType,
  -					RequestNum, State)
  +					RequestNum, State),
  +			{reply, Reply1, NewState1}
   	end;
   request1(?'DIAMETER_CC_APP_CC-REQUEST-TYPE_TERMINATION_REQUEST' = RequestType,
   		Request, SId, RequestNum, Subscriber, Balance, OHost, ORealm, State) ->
  
positive.code: 			'CC-Request-Number' = RequestNum, 'Granted-Service-Unit' = GrantedUnits},
  	Server = {Address, Port},
  	ok = ocs_log:acct_log(diameter, Server, accounting_event_type(RequestType), Request),
  	{reply, Reply, State}.
  
  -spec send_error(Request, SessionId, Subscriber, Balance, ResultCode, OriginHost, OriginRealm,
  		AuthAppId, RequestType, RequestNum, State) -> Result
  			when
  				Request ::#diameter_cc_app_CCR{},
  
negative.code: 				AuthAppId :: integer(),
  				RequestType :: integer(),
  				RequestNum :: integer(),
  				Result :: {Reply, State},
  				State :: state(),
  				Reply :: #diameter_cc_app_CCA{}.
  %% @doc Send CCA to DIAMETER client indicating a successful operation.
  %% @hidden
  generate_diameter_answer(Request, SId, _Subscriber, Balance, ResultCode, OHost, ORealm, AuthAppId, RequestType,
  		RequestNum, #state{address = Address, port = Port} = State) ->
  	GrantedUnits = #'diameter_cc_app_Granted-Service-Unit'{'CC-Total-Octets' = Balance},
  	Reply = #diameter_cc_app_CCA{'Session-Id' = SId, 'Result-Code' = ResultCode,
  