Refined while loop