fixed StackOverflow in TraceCounterexample;
converted tail recursion into a loop