Fix for sort functions