Use stack instead of heap for stream and etc.
Some trivial modifications.