Optimized some of the scripts, using argparse for options, centralized some common functions