working on inner loop