Changed null value check to use HasValue