change the condition to be ptr == NULL, not !=  Idiot