Make Damerau-Levenshtein sort case insensitive, fix some memory leaks.