fixed sorting algorithm