Refactored invites functionality to work better