Fixed error with closed stream.