ngram markov chain, contains a bug