significant refactoring for clarity of marginal