Fix some null pointer checks
Merge pull request #318 from LebedevRI/null-checks-0

Fix some null pointer checks