optimize grammar