Fixes threading problem with transactions

Fixes threading problem with transactions