Fix for unstable sort