Moved dynamic machine code to HasState and added allowed_roles for TransitionEvents