corrected some bugs with sorting