change foreach to map