Fix bug on null pointer array

Found null pointer array. Added if condition on several places.