in reply to Array behaving badly
Am I mistaken, I didn't see any "array" variable in your code whatsoever. Your second script is just the same thing with the first one. Please, the more detailed, if you want people's help.