import java.util.*;

public class MovementRoutine
{
    public MovementRoutine (String fullCommand, Vector<MovementFunction> functions, boolean debug)
    {
        _fullCommand = fullCommand;
        _functions = functions;
        _debug = debug;
    }

    public String getMainRoutine ()
    {
        /*
         * We know that Function A (1) is first in the sequence, followed by
         * B (2) and then C (3) is last but we don't know the order they follow
         * after the first.
         */

        String str = FunctionRoutine.ROUTINE_A;
        int index = _functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getLength();

        while (index < _fullCommand.length())
        {
            if (_fullCommand.startsWith(_functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getCommand(), index))
            {
                str += ","+FunctionRoutine.ROUTINE_A;

                index += _functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getLength();
            }
            else
            {
                if (_fullCommand.startsWith(_functions.elementAt(FunctionRoutine.ROUTINE_B_INDEX).getCommand(), index))
                {
                    str += str += ","+FunctionRoutine.ROUTINE_B;

                    index += _functions.elementAt(FunctionRoutine.ROUTINE_B_INDEX).getLength();
                }
                else
                {
                    if (_fullCommand.startsWith(_functions.elementAt(FunctionRoutine.ROUTINE_C_INDEX).getCommand(), index))
                    {
                        str += str += ","+FunctionRoutine.ROUTINE_C;

                        index += _functions.elementAt(FunctionRoutine.ROUTINE_C_INDEX).getLength();
                    }
                    else
                        System.out.println("Error, no functions found in commannd string "+_fullCommand);
                }
            }
        }

        return str;
    }

    private String _fullCommand;
    private Vector<MovementFunction> _functions;
    private boolean _debug;
}
@@ -648,55 +648,284 @@
     
-while (index %3C _fullCommand.length())%0A        %7B
+System.out.println(%22index %22+index);%0A        System.out.println(%22fullCommand %22+_fullCommand.length());%0A%0A        while (index %3C _fullCommand.length())%0A        %7B%0A            System.out.println(%22Searching for %22+_functions.elementAt(FunctionRoutine.ROUTINE_A_INDEX).getCommand());%0A
 %0A   
@@ -1235,32 +1235,154 @@
 e%0A            %7B%0A
+                System.out.println(%22Searching for %22+_functions.elementAt(FunctionRoutine.ROUTINE_B_INDEX).getCommand());%0A%0A
                 
@@ -1714,32 +1714,158 @@
               %7B%0A
+                    System.out.println(%22Searching for %22+_functions.elementAt(FunctionRoutine.ROUTINE_C_INDEX).getCommand());%0A%0A
                 
@@ -2203,32 +2203,54 @@
            else%0A
+                    %7B%0A
                 
@@ -2338,16 +2338,79 @@
 ommand);
+%0A%0A                        System.exit(0);%0A                    %7D
 %0A       

Update MovementRoutine.java