Refactor and add tests

I'm doing this as a prerequisite to adding checksums to the manifest json that gets shipped with the release. Adding checksums didn't fit cleanly into how the script already worked, so I wanted tests to be able to add the feature without breaking things.

ATM this is a work in progress, haven't wired everything up to the point where it's working as before.