Replace dirty database ops with transactions