changed stream code to avoid losing a data point when a packeket is prematurely closed