edit algorithm/sorting