Fixed null pointer errors.

Change-Id: Ib11abcf7ca37e3a6639b64dd3ffc46e398dd4500