Bug fix changing js global var to local variable