Improvements to transaction.
Fix a bug that makes the C++ version crash.