fixes #581: check for undefined instead of null