Set the scope after closing the stream
Fixes #1453
Fix merge