Fixed the exit from for loops