use argparse and a little refactoring