Fixed some bugs in reading from stdin