reduce
to_stream
added midpoint function