unglobaled avg and fixed seggy fault in do_sort