bayes_util code refactoring