Referral system

Closes #660.