ensure stable sort