Shortened code

I am able to decompose the code to a simple buffer and an output stream class that wraps it.