simplify while loop