Fix the transaction logic