fixed null pointer error and undefined variable error

Change-Id: I07f1021f22f44a9a1af21ecf9eeaf71e8b37787e