Fixed checks for NULL.