database transaction small refactoring