streaming example code improved