Fix JSHint errors and update tests

The first commit fixes or silences most of the reported JSHint errors.

The second commit fixes the remaining JSHint errors and adds tests to make sure that the changes are correct.