Added and tested code for refferal