added command line options which will override config file
added format option for text or csv (default is text)
split code up into functions to facilitate format option