Added command line script.
Added some error control and logging.