Less nested while loop