added argparse, and cleaned code