refactored loop code