change some for loop to lo-dash foreach