Correcting scope of variable calls

I don't understand how this ever worked in the first place.
Add an explanatory comment
Since terms won't always be present, make their usage conditional on their existence