Simplify while loop