improved stream/network code