marginal probaility functional but needs refactoring