fixed eof detection