Fixed issues with custom sort functions.