Fixed the NULL pointer dereferencing