Improve generate_metadata script