Improved loop detection with an option to run the automata until a loop is detected.