added EOF check