in reply to Redoing a script

So, where does the script you posted have problems? What have you tried to address these problems?