fixed several stream reading bugs