second part of section 3.5.3
add two funcs to stream
third part of section 3.5.3