Fixed bug in edit distance algorithm