Added detection for EOF