working for at least unigrams, but needs memory optimization.