Fix JavaScript issues found by the code inspector