Properly scope a local variable