Add cancel check to avoid continueing the task