Fixed some bugs in the task management