Fix replaceOutputWithVars
Add conditional statements