Check pointers before using them in var init

Pointer arguments are being used to initialize vars right before the pointers are checked for NULL.  Reorder code to avoid potential crashes.