Slightly refactored metadata generation functionality