I dunno, does it?

First:
I'm not being evasive; but when I script, I generally run something 100s of times and slowly debug things as I go. The only way you'll know it really works is just to try it.
On thing you'll find when you script is that you spend probably 10% of your time actually scripting, and 95% of your time debugging (math error intentional....)
Second:
Please check with 12X to make sure it's ok to re-post his code. It's not good form here to post the work of other without their permission..
Third:
In order to wrap your posted code, you need code tags. For that you wrap the posted code with {code] and {/code] (replace "{" with "[")