added an exit to the loop