Fix some bugs dealing with invoices.