change sort to stable_sort, prevent dropping data