sorting output bug fixed