consolidate duplicated code
handle plugin cancellation properly