Added more logic for handling Invitations