Refactored Ngram Generation to make it a little more memory efficient