Fix for transaction left uncommitted.
Tidyups ... mostly cosmetic