Add null check and log