Replace map() with a more universal solution