edit distance reimpl