Re-factor metadata generator script