N-gram implementation updated