invite functiopn refactoring