Refactor 'edit distance'.