Replaced map with foreach