Refactor, clean up of stream code.