separated data collection from main function
merged Jame's and Brett's commits