ref 1
changed  to 'while' loop