add handling of cancelling