Changed code for "while"