fixed edit distance algorithm