Cleaned up _calc_edit_dist()