Here's the script that's been causing the problem. It worked fine until I upgraded to 4.0.1.
Thanks Levi, I've figured out what was wrong and fixed this in 4.0.2 released today :-) Thanks for raising this