Fixing variable substitution error