Fix bug with sorting tasks