updated and tested metadata retrieval routine