Initial merge into juju repository

This PR is the initial merge of previous work into the juju/jujusvg repository.
or, put this block into a separate function.
The defer idiom seems like a reasonable fit here.