fixed error handling for io.EOF