fixed sorting in heuristic