Added argparse support and improved exception handling