This does some code cleanup to avoid duplication, improves the logs, and records min and max values as well as the mean.