Improvements to ngram class.