Add set_group_membership method and improve error handling