Fixed issue with js global variables on general functions