Fix null pointer errors.

PR#3394