refactor to use argparse rather than getopt