reorganize cartdata code