rewrote stream functions