Lots of fixes for transactions