refactor ngrams