replaced sorting routine, speed improved 1/3