Refactor chunked_stream.js