move more common code in anticipation of adding more scripts to compute posterior expectations