Working version of Hierarchical Bayesian trial model. Results need more testing