Fix code layout.
Insert more checking for "isCancelled()", this way the async bug seems
disappeared.