protected Element createStateElement(Document document, State state,
			Automaton container) {
		// Start the creation of the state tag.
		Element se = createElement(document, STATE_NAME, null, null);
		se.setAttribute(STATE_ID_NAME, "" + state.getID());
		// Encode position.
		se.appendChild(createElement(document, STATE_X_COORD_NAME, null, ""
				+ state.getPoint().getX()));
		se.appendChild(createElement(document, STATE_Y_COORD_NAME, null, ""
				+ state.getPoint().getY()));
		// Encode label, if set.
		if (state.getLabel() != null)
			se.appendChild(createElement(document, STATE_LABEL_NAME, null,
					state.getLabel()));
		// Encode the name, if set.
		if (state.getName() != null) se.setAttribute(STATE_NAME_NAME, "" + state.getName());
		// Encode whether the state is initial.
//		State parent = state.getParentBlock();
//		Automaton a = null;
//		if (parent != null) {
//			a = (Automaton) container.getBlockMap().get(
//					parent.getInternalName());
//		}
//		if (a == null) {
//			a = container;
//		}

        //MERLIN MERLIN MERLIN MERLIN MERLIN//
        Automaton a = state.getAutomaton();
		if (a.getInitialState() == state)
			se.appendChild(createElement(document, STATE_INITIAL_NAME, null,
					null));
		// Encode whether the state is final.
		if (a.isFinalState(state))
			se.appendChild(createElement(document, STATE_FINAL_NAME,
							null, null));

		// Return the completed state encoding element.
		return se;
	}