fix a JS infinite loop