added priority-sorting of tasks