use dnmlib for ngram search, fixed some memory leaks