Update addJavascriptVar function to use Array and "other" minor changes

Most of the change was the update to the addJavascriptVar function to use arrays so it can be called once with several elements.

Other changes are as noted in the commit comments, couple of small bugs or tweaks