Javascript tidy-up

The Javascript could use some love, but before even attempting to do that, reformatting the code and fixing some typos is necessary. These two commits address these issues so that deeper work can be done with ease afterwards.