make sure streams get closed