Fixed to work in IE8.

Additional minor code improvements inspired by jslint.