* sleep is a deprecated keyword. Use wait() with negative values instead.
* refresh is a deprecated keyword. You can simply omit it.

Besides your script looks correct. Can you give any closer circumstances where the bug occurs?


Always learn from history, to be sure you make the same mistakes again...