1) fixup for input_iterator returned value so it can return  and 0 for processing. only undef is considered as EOF. 2) made some explanation on inner loop logic