test and fix ngrams implementation