Fix various race conditions in sim.js initialisation