Implements incremental edit distance calculation and performance improvements.