refactored loop construct