Fix 'Stack too deep' error with a while loop.