sort and swap works