Fixing bug in sort.