invite function refactoring