only set metadata if metadata dictionary is defined.