sorting: convert to stable sort