updated script so it works from the commandline