Restructure to put all the streaming code in one place.