cleaned up marginal calculations