anchor.diff:  		false ->
   			0
   	end,
  -	rate5(Subscriber, Price, Validity, Flag,
  -			DebitAmount, ReserveAmount, SessionAttributes, Rated).
  -%% @hidden
  -rate5(#service{buckets = Buckets1} = Subscriber,
  +	rate5(Service, Buckets, Price, Flag, DebitAmount, ReserveAmount, State).
  +%% @hidden
  +rate5(Service, Buckets1,
   		#price{units = Units, size = UnitSize, amount = UnitPrice},
  -		_Validity, initial, 0, ReserveAmount, SessionAttributes, Rated) ->
  -	SessionId = get_session_id(SessionAttributes),
  +		initial, 0, ReserveAmount, #{session_id := SessionId} = State) ->
   	case reserve_session(Units, ReserveAmount, SessionId, Buckets1) of
   		{ReserveAmount, Buckets2} ->
  -			rate6(Subscriber#service{buckets = Buckets2},
  -					initial, 0, 0, ReserveAmount, ReserveAmount,
  -					SessionId, Rated);
  +			rate6(Service, Buckets2, initial,
  +					0, 0, ReserveAmount, ReserveAmount, State);
   		{UnitsReserved, Buckets2} ->
   			PriceReserveUnits = (ReserveAmount - UnitsReserved),
   			{UnitReserve, PriceReserve} = price_units(PriceReserveUnits,
   					UnitSize, UnitPrice),
   			case reserve_session(cents, PriceReserve, SessionId, Buckets2) of
   				{PriceReserve, Buckets3} ->
  -					rate6(Subscriber#service{buckets = Buckets3},
  -							initial, 0, 0, ReserveAmount,
  -							UnitsReserved + UnitReserve, SessionId, Rated);
  +					rate6(Service, Buckets3, initial, 0, 0,
  +							ReserveAmount, UnitsReserved + UnitReserve, State);
   				{PriceReserved, Buckets3} ->
  -					rate6(Subscriber#service{buckets = Buckets3},
  -							initial, 0, 0, ReserveAmount,
  -							UnitsReserved + (PriceReserved div UnitPrice),
  -							SessionId, Rated)
  +					rate6(Service, Buckets3, initial, 0, 0, ReserveAmount,
  +							UnitsReserved + (PriceReserved div UnitPrice), State)
   			end
   	end;
  -rate5(#service{enabled = false, buckets = Buckets1} = Subscriber,
  +rate5(#service{enabled = false} = Service, Buckets1,
   		#price{units = Units, size = UnitSize, amount = UnitPrice},
  -		_Validity, interim, DebitAmount, _ReserveAmount,
  -		SessionAttributes, Rated) ->
  -	SessionId = get_session_id(SessionAttributes),
  +		interim, DebitAmount, _ReserveAmount,
  +		#{session_id := SessionId} = State) ->
   	case update_session(Units, DebitAmount, 0, SessionId, Buckets1) of
   		{DebitAmount, 0, Buckets2} ->
  -			rate6(Subscriber#service{buckets = Buckets2}, interim,
  -					DebitAmount, DebitAmount, 0, 0, SessionId, Rated);
  +			rate6(Service, Buckets2, interim,
  +					DebitAmount, DebitAmount, 0, 0, State);
   		{UnitsCharged, 0, Buckets2} ->
   			PriceChargeUnits = DebitAmount - UnitsCharged,
   			{UnitCharge, PriceCharge} = price_units(PriceChargeUnits,
   					UnitSize, UnitPrice),
   			case update_session(cents, PriceCharge, 0, SessionId, Buckets2) of
   				{PriceCharge, 0, Buckets3} ->
  -					rate6(Subscriber#service{buckets = Buckets3}, interim,
  -							DebitAmount, DebitAmount + UnitCharge, 0, 0,
  -							SessionId, Rated);
  +					rate6(Service, Buckets3, interim, DebitAmount,
  +							DebitAmount + UnitCharge, 0, 0, State);
   				{PriceCharged, 0, Buckets3} ->
  +					%% @todo generate unique bucket id
   					Buckets4 = [#bucket{remain_amount = PriceCharged - PriceCharge,
   							units = cents} | Buckets3],
  -					rate6(Subscriber#service{buckets = Buckets4}, interim, DebitAmount,
  -							UnitsCharged + (PriceCharged div UnitPrice), 0, 0,
  -							SessionId, Rated)
  +					rate6(Service, Buckets4, interim, DebitAmount,
  +							UnitsCharged + (PriceCharged div UnitPrice), 0, 0, State)
   			end
   	end;
  -rate5(#service{buckets = Buckets1} = Subscriber,
  +rate5(Service, Buckets1,
   		#price{units = Units, size = UnitSize, amount = UnitPrice},
  -		_Validity, interim, DebitAmount, ReserveAmount,
  -		SessionAttributes, Rated) ->
  -	SessionId = get_session_id(SessionAttributes),
  -	case update_session(Units, DebitAmount, ReserveAmount,
  -			SessionId, Buckets1) of
  +		interim, DebitAmount, ReserveAmount, #{session_id := SessionId} = State) ->
  +	case update_session(Units, DebitAmount, ReserveAmount, SessionId, Buckets1) of
   		{DebitAmount, ReserveAmount, Buckets2} ->
  -			rate6(Subscriber#service{buckets = Buckets2}, interim,
  -					DebitAmount, DebitAmount, ReserveAmount,
  -					ReserveAmount, SessionId, Rated);
  +			rate6(Service, Buckets2, interim, DebitAmount,
  +					DebitAmount, ReserveAmount, ReserveAmount, State);
   		{DebitAmount, UnitsReserved, Buckets2} ->
   			PriceReserveUnits = ReserveAmount - UnitsReserved,
   			{UnitReserve, PriceReserve} = price_units(PriceReserveUnits,
   					UnitSize, UnitPrice),
   			case update_session(cents, 0, PriceReserve, SessionId, Buckets2) of
   				{0, PriceReserve, Buckets3} ->
  -					rate6(Subscriber#service{buckets = Buckets3}, interim,
  -							DebitAmount, DebitAmount, ReserveAmount,
  -							UnitReserve, SessionId, Rated);
  +					rate6(Service, Buckets3, interim, DebitAmount,
  +							DebitAmount, ReserveAmount, UnitReserve, State);
   				{0, PriceReserved, Buckets3} ->
  -					rate6(Subscriber#service{buckets = Buckets3}, interim,
  -							DebitAmount, DebitAmount, ReserveAmount,
  -							UnitsReserved + PriceReserved div UnitPrice,
  -							SessionId, Rated)
  +					rate6(Service, Buckets3,
  +							interim, DebitAmount, DebitAmount, ReserveAmount,
  +							UnitsReserved + PriceReserved div UnitPrice, State)
   			end;
   		{UnitsCharged, 0, Buckets2} ->
   			PriceChargeUnits = DebitAmount - UnitsCharged,
  
positive.code: 			{error, Reason}
  	end.
  %% @hidden
  rate1(Protocol, ServiceType, Subscriber, Timestamp, Address, Direction,
  		#offer{specification = undefined, bundle = Bundle},
  		Validity, Flag, DebitAmounts, ReserveAmounts, SessionAttributes) ->
  	try
  		F = fun(#bundled_po{name = OfferId}, Acc) ->
  				case mnesia:read(offer, OfferId, read) of
  
negative.code: 		false ->
  			throw(undefined_tariff)
  	end;
  rate3(Protocol, Service, Buckets, _Address,
  		Price, Flag, DebitAmounts, ReserveAmounts, State) ->
  	rate4(Protocol, Service, Buckets, Price,
  			Flag, DebitAmounts, ReserveAmounts, State).
  %% @hidden
  rate4(_Protocol, #service{enabled = false} = Service,
  		Buckets, _Price, initial, _DebitAmounts, _ReserveAmounts, State) ->
  	rate6(Service, Buckets, initial, 0, 0, 0, 0, State);
  rate4(radius, Service, Buckets, Price, initial, [], [], State) ->
  	rate5(Service, Buckets, Price, initial, 0, get_reserve(Price), State);
  rate4(radius, Service, Buckets, #price{units = Units} = Price,
  		interim, [], ReserveAmounts, State) ->
  	ReserveAmount = case lists:keyfind(Units, 1, ReserveAmounts) of
  		{_, ReserveUnits} ->
  			ReserveUnits + get_reserve(Price);
  		false ->
  			get_reserve(Price)
  	end,
  	rate5(Service, Buckets, Price, interim, 0, ReserveAmount, State);
  rate4(_Protocol, Service, Buckets, #price{units = Units} = Price,
  		Flag, DebitAmounts, ReserveAmounts, State) ->
  	DebitAmount = case lists:keyfind(Units, 1, DebitAmounts) of
  		{_, DebitUnits} ->
  			DebitUnits;
  