Fixed a possible exception when cancelling jobs.