Replaced for in loop with Array.foreach