refactor setCancelled method