Updated to account for discounts. Still not tested.
Removing errors.