reorganized code a little to separate out argument parsing / provide better error message; fixed small timing issue