Fix null pointer issue