This is mostly just adding some Null guards ahead of code that was already dereferencing pointers, so there should be no change in behavior. Also adds one validation of an array index that was drawing a complaint.