Added npe avoidance check