Fix eof_ending problem