Fix transaction logic