more efficient looping across ngrams