fixed a bug with variable substitution