Added a check for NULL pointer.