Changed marginalize function according to new representation