Added missing nullpointer check