Replace foreach with lambda