Fixed the loop issue