Add many missing NULL checks