fix an issue with buffering and EOF