Move stream management helpers out to separate file