Fixed hungs at EOF with an ugly hack.