Adds better group memberships implementation

Adds shorten implementation of memberships which also strips out duplicates