Added command line handling logic so program can be run from command line.