added sorting to sort pending to the top of tasks