Simplify/refactor group membership code.