Add guard to setTimeout

As the runtime might have been destroyed before the function executes, causing errors.