Improve metadata handling