on the fly sort changed to merge sort