Fixed sorting of tasks