Fixed stream not set to nil when error occurs when opening