improve last commit to not iterate over all invoices