actually move the sort out of loop