Fix improperly referenced variables

Issue #2424