Moved test for keepGoing into for loops