reorganize the code to prepare to add an interface to compute posterior expectations