Fix IO and close order.