support unsorted input data