Refactored ngram count model to improve efficiency.