refactored loop iteration and generator behaviour