improve modular code in validateResponse and confirmInvite