Refactor replace_vars: don't make replacement values static unless we're sure they're not related to the passed object