Can you post the part of the script where the first error occurs? Including the error message.
And please insert tags in your reply and paste the codefragment between them. You can insert these tags by clicking the thirdmost right button above the edit pane.
Hans