added inner loop