simplify the while loop in text parser