Refactor out to script to fix env var subst