Using stable_sort instead of sort