refactor stream.js