fix marginals and add max-marginal inference