Fixed variable scoping problem