minor fix to write_data() for EOF handling