Better null checks

Fixes #661. Can be tested with this jar set: [Dropbox](https://www.dropbox.com/s/y063e5nlu9yg42m/ProjectRed-1.7.10-4.5.7.59-npe-fix.zip?dl=0)