better edit distance code