adding totals, cleaning up code