updated loop

Bug fixes