Added ngram implementation, minor fixes