[WIP] a couple of improvements to the js, no functional changes at all

I'll consolodate this code to use the other function rather than redefine everything