adjusting the while function