Fixed multiple-connections bug in GlobalStateMachine and added a couple of new tests