better database transaction handling