Miscellaneous fixes and improvements to the javascript code