making the logic more resilient for nulls