Refactor to avoid duplicate invoices