Fixed logic error in handling EOF.