sort and compare