Added command line switches and stdin support