Bug fixes for script function calls.
Implement per-thread event queues.