Improved metadata handling and tests.