Script doesn't run first time

I’m sorry that I can’t help with scripting but unfortunately that would end up being an all-consuming black hole and we’d never get any GP code written!

However, if I may add a suggestion – I strongly urge you to liberally comment the code you’ve written. Otherwise, you’ll come back to it in a few months and forget completely what you did and why.