anchor.diff:      Now = util:timestamp(),
       LocationStr = url_to_requristr(Location),
   
  -    F = fun() ->
  -		mnesia:select(phone,
  -			      [{#phone{number = SipUser,
  -				       requristr = LocationStr,
  -				       _ = '_'},
  -				[{'>', {element, #phone.expire, '$_'}, Now}],
  -				['$_']
  -			       }])
  -	end,
  -    mnesia:transaction(F).
  +    %% query on requristr since that is most likely unique
  +    F = fun() ->
  +		mnesia:index_read(phone, LocationStr, #phone.requristr)
  +	end,
  +    {atomic, L} = mnesia:transaction(F),
  +
  +    %% remove entrys which are expired, or don't have #phone.number == SipUser
  +    Res = [E || E <- L, E#phone.expire > Now orelse E#phone.expire == never, E#phone.number == SipUser],
  +
  +    {atomic, Res}.
   
   
   %%--------------------------------------------------------------------
  
positive.code: %% Descrip.: find all users (#phone.number) that use a cretain sip url
  %% Returns : {atomic, Users} | {aborted, Reason}
  %%           Users = list() of #phone.number values
  %% XXX this function is inefficient, as no keys are used during search
  %%--------------------------------------------------------------------
  get_sipusers_using_location(URI) when is_record(URI, sipurl) ->
      ReqURIstr = url_to_requristr(URI),
      F = fun() ->
  		[ E#phone.number || E <- mnesia:match_object(#phone{requristr = ReqURIstr,
  								    _ = '_'}) ]
  	end,
      mnesia:transaction(F).
  
  
negative.code:     %% without requiring authorization in incomingproxy and appserver.
      URIstr = url_to_requristr(Address),
      Fun = fun() ->
  		  %% query on requristr since that is most likely unique
  		  L = mnesia:index_read(phone, URIstr, #phone.requristr),
  		  %% apply our other selection criterias as well
  		  A = [E || E <- L, E#phone.number == SipUser, E#phone.class == Class],
  
  		  Delete = fun(O) ->
  				   mnesia:delete_object(O)
  			   end,
  