Fix variable scoping bug introduced in last commit