end document bug fixed