js variable scope fix