Added a check for NULL.