Add and clean-up null-checks.

Change-Id: I4af4c6c3342f19cfc93a27c42ff150818c812e2b