Modified code to check if the object has required property before
further processing.