fix var scoping bug