Fixed issue when canceling tasks