Write tests for Ngrams and fix a bug