Added repeat condition for inner loop.