Added null check required to work with IE8.

Encountered problem in IE8 without the null check.