fixed end of file detection