Check for null pointer before use
Merge pull request #55 from maksqwe/null_deref_fix

Check for null pointer before use