fixed bugs when stopping a task