Manage stream termination properly