Rewriting update_invoices with $a and $b in sort and reduce