rearranging database transaction