do a third rewrite of sorting