Made some improvements to handle regex escaping on the input. renamed vars for indexing ngram table and last N words