Comments and some slight code cleanup

Added quite a bit of comments to the scripts and functions.  Made some
small changes to the code, but for the most part, it's clear enough
as-is, and probably not worth any more time (or money) to try to
refactor it further.