Refactored code for invites