Added defensive nullness checks