Move the call to cancel_timer to the right place