fix bug when pointer in loop