Fixing an issue in sort