fixed EOF detection