refactored to one each loop