Fixed closing a stream