Fixed a variable scoping issue