Moved state machines onto components and added a globalvars module.