transaction handling in try-with-resource around init
also small refactoring