private static MealyAutomaton removeDeadEnds(MealyAutomaton automaton) {
		MealyAutomaton currentA = automaton;
		while (true) {
			boolean changed = false;
			MealyAutomaton newA = new MealyAutomaton(automaton.stateCount());
			boolean[] deadEnd = new boolean[automaton.stateCount()];
			for (int i = 0; i < automaton.stateCount(); i++) {
				if (currentA.state(i).transitions().isEmpty()) {
					deadEnd[i] = true;
				}
			}
			for (int i = 0; i < automaton.stateCount(); i++) {
				for (MealyTransition t : currentA.state(i).transitions()) {
					if (!deadEnd[t.dst().number()]) {
						newA.addTransition(newA.state(i), new MealyTransition(newA.state(i),
								newA.state(t.dst().number()), t.event(),
								t.expr(), t.actions()));
					} else {
						changed = true;
					}
				}
			}
			if (!changed) {
				return currentA;
			}
			currentA = newA;
		}
	}