@Override
        public void apply(StateMachineWrapperAcceptor<EventType> machine, StateMachineWrapperAcceptor<EventType> wrapped)
                throws FSMWrapperException {
            if (wrapped instanceof FSMWrapper) {
                wrapped.acceptWrapperTransport(this);
            } else {
                if (builder != null) {

                    try {
                        StateMachineDriver<EventType> wrappedFSM = (StateMachineDriver<EventType>) wrapped;
                        HashMap<Object,Object> savedFSMProperties = builder.getFSMProperties();
                        StateMachineDriver<EventType> newFSM = (StateMachineDriver<EventType>) builder
                                .addFSMProperties(wrappedFSM.getFSMProperties()).build(
                                new ProvidedOrCopyFromFSMFactory(newStates, wrappedFSM), true);
                        builder.setFSMProperties(savedFSMProperties); //restore original properties
                        newFSM.setCurrentNode(wrappedFSM.getNameOfCurrentState());
                        ((StateMachineWrapper) machine).replaceWrappedWith(newFSM);
                    } catch (BadStateMachineSpecification ex) {
                        this.ex = ex;
                    } /*finally {
                     latch.countDown();
                     }*/

                } else {
                    if (newStates != null) {
                        for (HashMap.Entry<String, State<EventType>> pair : newStates.entrySet()) {
                            FSMNode<EventType> node = ((StateMachineDriver) wrapped).getNodeByName(pair.getKey());
                            if (node == null) {
                                ex = new BadStateMachineSpecification(pair.getKey() + " is not known state");
                                return;
                            }
                            node.setState(pair.getValue());
                            try {
                                pair.getValue().onStateAttachedToFSM(null, (FSMStateView) wrapped);
                            } catch (BadStateMachineSpecification ex) {
                                this.ex = ex;
                                return;
                            }
                        }
                    }
                }
            }
        }