Fixed the loop bug

Fixed the loop bug