Fixes a bug where the wrong value is used in calculating the sorted order