sort and simplify