some modification in the element reordering which should solve some problems caused by the fact that qsort may handels == items differently on different platform.