Fix jshint and style issues.

I tweaked the jshint file slightly, sorted it, and then fixed all the errors it gave about the code. This is important because running `grunt` with no arguments fails if jshint isn't happy.