Pure shot in the dark... what happens if you take the Freeimage command away?
You might want to add a a few debug commands in as well so you can trace the loop through your for/each statements.
You might want to add a a few debug commands in as well so you can trace the loop through your for/each statements.