working version of metadata collection script