Several Javascript fixes and improvements