extracted variable substitution functionality from env-backward-base
  so I can focus on the actual inference mechanism