add some guards for nil pointers