Optimize creating groups