Fix variable referencing bugs.