Refactored ngram model.