Fix 'reached end of stream for null'