Added N-gram algorithm.