change the way to generate optgroups
remove unused variables