this is copy/pasted/edited from deploy, but IMO that's fine since we may branch this version anyways and it's not totally clear that there's modular bits that should be pulled out.