fix var scoping issues