adding ability to specify total as a function, and adding example of giving complete control of the data to the caller