Made the job cancel code account for more situations.