Fixed toTask cleanup and termination reason propagation