Check for undefined to resolve #173

Resolve issue #173