fix bug and change count_running_tasks()