Refactored metadata reading