fixed handle transactions, added tests