Major upgrade

I've attempted to pull in what I could from other open PRs, added tests, and made everything idempotent.  Take a look.