Added code to allow script to be run from the command line