Correct edit distance calculation