make sure stream is not closed by streamwriter; closes #163