finished conversion from map to for loop