refactor transaction management