improve sort method