Rewriting remove_ignored_grams to be a loop of small queries rather than one large query