fix bug in visit while loop