Fixing sorting problem