Added tests for total and average rows.
Refactored code for displaying the heading row.