perhaps we can move the part that's not submission-specific up, out of the loop (around line 90)