simplifying grammar loops