Added a couple more checks for NULL.