Fix database transaction and improve debygging log