working but infinite loop
works for one record