Changed while to upto