Fixing null pointer issue