fixed EOF check