Adds more undefined checks to all functions called via setTimeout.

There seems to be a lot more unexpected race conditions if you deactivate the editor from other event handlers.
By checking that properties are defined before accessing these errors should be fixed.