replaced for-loops with Array.map