added Prof.  Norvig's code  for referral