updated sorting algo

UNTESTED
fixed syntax bugs
fixed some bugs

running tallys aren't quite right.  Also M2/Var/stdev broken
fixed repeated order case

avg/stdev/var/M2 still broke