moved a lot of stuff around to break things out into functions.  also added a main function.  code isn't working at the moment.  probably lots of bugs.  still need to add argparse.