fixing issue where only the last group was kept when permissions are applied