Fixed some bugs in transaction handling. [skip ci]