Fixed sorting problems