Fixed issue with closed streams