Code updated for null check