new stream module in the core lib, refcounting mechanism to preserve nested stream lifetime