Added protection for null pointer