Fix infinate loop bug

I had to set result equal to getNextState and retrun result for the recursion to work.  I also fixed some test cases for ID and UNDEFINED.