Added extra null check

Null check provides a fix for the bug in issue #460