fix bugs with corrupt streams