code misordered for sort