Fixes local variable scoping