orig with changes through while loop