Levenshtein distance algorithm implementation