EOF behavior for stdin; Fix some bugs;