Make sort_by be a stable sort