Re-implemented apply referral code