Refactor.  Replaced a few comments with functions.
Options passed as command line arguments rather than environment variables.