corrected error in ordering function