Refactor part of marginal mlogregr (unfinished)