Added a check for metadata validity.