Added closed = true to avoid infinite loop where closed is always false

and stream is not null