fixed write after terminate