added additional logging and transactions around sql statements