restructured the database transaction logic. I commented my changes in a log as well