client side: extract streaming code into separate file