Simplify needOptgroup function