Fix crash with script timers, and other fixes

Stuff I found in the process of working on incremental layout.