Collect foreach var in main function