Improved while-loop