rewrite events.js and streams.js. add automatic option collecting