refactor cancel handling