cleanup of some code and adding option to template aggregate rows.