anchor.diff:  		end,
   		case lists:foldl(F, [], Bundle) of
   			[#offer{} = Offer | _] ->
  -				authorize2(Protocol, ServiceType, Subscriber, Offer,
  +				authorize2(Protocol, ServiceType, Service, Buckets, Offer,
   						Timestamp, Address, Direction, SessionAttributes, Reserve);
   			[] ->
  -				authorize5(Subscriber, ServiceType, SessionAttributes, Attributes)
  +				authorize5(Service, Buckets, ServiceType, SessionAttributes, Attributes)
   		end
   	catch
   		_:_ ->
   			throw(invalid_bundle_product)
   	end;
   authorize2(radius = Protocol, ServiceType,
  -		#service{attributes = Attributes} = Subscriber,
  -		#offer{specification = ProdSpec, price = Prices},
  -		Timestamp, Address, Direction, SessionAttributes,
  -		Reserve) when (Reserve > 0)
  +		#service{attributes = Attributes} = Service, Buckets,
  +		#offer{specification = ProdSpec, price = Prices}, Timestamp,
  +		Address, Direction, SessionAttributes, Reserve) when (Reserve > 0)
   		and ((ProdSpec == "9") orelse (ProdSpec == "5")) ->
   	F = fun(#price{type = tariff, units = seconds}) ->
   				true;
  
positive.code: 	end,
  	case lists:any(F, Buckets) of
  		true ->
  			authorize6(Subscriber, SessionAttributes, Attributes);
  		false ->
  			{unauthorized, out_of_credit, ExistingAttr}
  	end.
  %% @hidden
  authorize6(#service{multisession = false, session_attributes = []}
  		= Subscriber, SessionAttributes, Attributes) ->
  	NewSessionAttributes = {erlang:system_time(?MILLISECOND),
  			get_session_id(SessionAttributes)},
  	Subscriber1 = Subscriber#service{session_attributes =
  		[NewSessionAttributes], disconnect = false},
  	ok = mnesia:write(Subscriber1),
  	{authorized, Subscriber1, Attributes, []};
  authorize6(#service{multisession = false, session_attributes
  		= ExistingAttr} = Subscriber, SessionAttributes, Attributes) ->
  	NewSessionAttributes = {erlang:system_time(?MILLISECOND),
  			get_session_id(SessionAttributes)},
  	Subscriber1 = Subscriber#service{session_attributes =
  		[NewSessionAttributes], disconnect = false},
  	ok = mnesia:write(Subscriber1),
  	{authorized, Subscriber1, Attributes, ExistingAttr};
  authorize6(#service{multisession = true, session_attributes
  		= ExistingAttr} = Subscriber, SessionAttributes, Attributes) ->
  	NewSessionAttributes = {erlang:system_time(?MILLISECOND),
  			get_session_id(SessionAttributes)},
  	Subscriber1 = Subscriber#service{session_attributes =
  		[NewSessionAttributes | ExistingAttr], disconnect = false},
  	ok = mnesia:write(Subscriber1),
  	{authorized, Subscriber1, Attributes, ExistingAttr}.
  
  -spec session_attributes(Attributes) -> SessionAttributes
  	when
  
negative.code: 	end.
  %% @hidden
  authorize1(radius, ServiceType,
  		#service{attributes = Attributes, product = ProdRef} =
  		Service, Timestamp, Address, Direction, SessionAttributes) ->
  	case mnesia:read(product, ProdRef, read) of
  		[#product{characteristics = Chars,
  				product = OfferId, balance = BucketRefs}] ->
  			Buckets = lists:flatten([mnesia:select(bucket,
  					[{'$1', [{'==', Id, {element, #bucket.id, '$1'}}], ['$1']}])
  					|| Id <- BucketRefs]),
  			F = fun({'Session-Id', _}) ->
  					true;
  				({?AcctSessionId, _}) ->
  					true;
  				(_) ->
  					false
  			end,
  			case lists:any(F, get_session_id(SessionAttributes)) of
  				true ->
  					case lists:keyfind("radiusReserveSessionTime", 1, Chars) of
  						{_, RRST} when is_integer(RRST) ->
  							case mnesia:read(offer, OfferId, read) of
  								[#offer{} = Offer] ->
  									authorize2(radius, ServiceType, Service, Buckets, Offer,
  											Timestamp, Address, Direction, SessionAttributes, RRST);
  								[] ->
  									throw(offer_not_found)
  							end;
  						false ->
  							authorize5(Service, Buckets, ServiceType, SessionAttributes, Attributes)
  					end;
  				false ->
  					authorize5(Service, Buckets, ServiceType, SessionAttributes, Attributes)
  			end;
  		[] ->
  			throw(product_not_found)
  	end;
  authorize1(diameter, ServiceType,
  		#service{attributes = Attributes, product = ProdRef} =
  		Service, _Timestamp, _Address, _Direction, SessionAttributes) ->
  	case mnesia:read(product, ProdRef, read) of
  		[#product{balance = BucketRefs}] ->
  			Buckets = lists:flatten([mnesia:select(bucket,
  					[{'$1', [{'==', Id, {element, #bucket.id, '$1'}}], ['$1']}])
  					|| Id <- BucketRefs]),
  			authorize5(Service, Buckets, ServiceType, SessionAttributes, Attributes);
  		[] ->
  			throw(product_not_found)
  	end.
  %% @hidden
  authorize2(radius = Protocol, ServiceType,
  		#service{attributes = Attributes} = Service, Buckets, Timestamp,
  		#offer{specification = undefined, bundle = Bundle}, Address, Direction,
  		SessionAttributes, Reserve) when Reserve > 0, Bundle /= [] ->
  	try
  		F = fun(#bundled_po{name = OfferId}, Acc) ->
  				case mnesia:read(offer, OfferId, read) of
  