Added null check required to work with IE8.

Encountered problem in IE8 without the null check.
Merge pull request #1 from pthorin/master

Added null check required to work with IE8.

thanks