improve processing time by doing partial sort