Added check for termination as well as cancellation.