added some new testing for loop breaking; refactored code