Fix variable scoping :bug: