Cleaned up loops in TaskManager's cancelTask().