corrected logic, and added subtotal lines for easier reading.