Trigrams implemented efficiently