Added findNextToken helper function