Better JS variable scoping