Fixed sorting problem