refactored and debugged transaction insert