fixes issue #1033.
Merge pull request #1035 from ne0fhyk/fix_issue_1033

Fixes possible NPE (#1033)