Changed to correctly identify the end of input stream (^D).