How can this function ever return NULL?