Better handing for close output streams