use appropriate loop when assigning header metadata to document