replaced Array.map by for loops