refactored
refactored the loop