Refactor function, which validate memberships.