Move around some code to check for NULL pointer

A pointer was being used before a check for NULL value